...

View Full Version : Grrr!!! Validator problem



msNewbie
11-30-2012, 03:19 AM
What am I doing wrong?
The program works until I try to add the validator.
BTW there are more functions beside m_to_k
I still have a bunch more to do on this homework and this is driving me nutz!
The HTML is the easy part!


function validator()
var MINNUM = <1;
var MAXNUM = >1000000;
//Validate the inputted meters
while((isNaN(meters)) || (meters < MINNUM) || (meters > MAXNUM))
{
alert("Invalid digit entered. Must be between 1 & 1000000.");
return result;
};

var report = function(meters,kilometers)
{
document.getElementById("result").innerHTML = //"result" gets sent to the HTML page where it is being asked for
meters + " meters are equal to " + kilometers + " kilometers";
//is just the text that will show up on the monitor. meters + is what the user typed in. The space after the quotations will insert what was typed in by the user then the text shows up (meters are equal to). + kilometers + inserts the caculation below. The space after the quotations will insert what was caculated. Then the text shows up (kilometers).
};

document.getElementById("m_to_k").onclick = function() // after the user types in the digits the user will click on the button of choice which will preform the caculation below.
{
var meters = document.getElementById("distance").value; //meters will be equal to what the user typed in and be sent to report
var kilometers = (meters *.001); //kilometers will be equal to the caculation in parenthises and will send it to report

report(meters, kilometers); //this report has the information of the digits that were entered (meters) plus the caculation (kilometers) that will be grabbed by the HTL page to be displayed.
};

Philip M
11-30-2012, 07:23 AM
var MINNUM = <1;
var MAXNUM = >1000000;


Not valid syntax. Omit the < and >.

Your error console ought to have revealed that.


It is your responsibility to die() if necessary….. - PHP Manual

msNewbie
11-30-2012, 12:03 PM
<1 means less that one
>100000 means more than 1000000
instructor uses that all the time

msNewbie
11-30-2012, 12:36 PM
I forgot to say that #1 I am still up working on this and I did make a correction I forgot the parenthesis around the <1 & the >1000000
So it does look like this (but still does not work):


function validator()
var MINNUM = (<1);
var MAXNUM = (>1000000);
//Validate the inputted meters
while((isNaN(meters)) || (meters < MINNUM) || (meters > MAXNUM))
{
alert("Invalid digit entered. Must be between 1 & 1000000.");
return result;
};


When I insert a letter instead of a digit I get this:
meters equals NaNa kilometers you have traveled
instead of this:
Invalid digit entered. Must be between 1 & 1000000.
and
it is in the same place as where the calculation is and not an alert box
BTW
Anyway to change the color of the font there in the calculation?

Philip M
11-30-2012, 01:14 PM
One more tine - the value of a numeric variable must be a number and may not include signs such as < or >. Whether or not in brackets. If your tutor says otherwise, get a new tutor.




<script type="text/javascript">

function validator(meters) {
var MINNUM = 1;
var MAXNUM = 100000;
meters = meters *1; // make meters a number
if ((isNaN(meters)) || (meters < MINNUM) || (meters > MAXNUM)) {
alert("Invalid value entered. Must be a number between 1 & 1000000.");
return false;
}
}

validator(-1); // a number out of range
validator("xyz"); // a string

</script>

You can of course have if (meters > 100) or whatever.

You cannot change the font or other styling of the built-in alert box. Use a <span> styled with CSS instead.

msNewbie
11-30-2012, 01:33 PM
I removed my validation and inserted your validation and it does not work

msNewbie
11-30-2012, 01:37 PM
I have not gone to sleep all night long racking my brains out on this and have to leave for school in a little while
Here is the entire code.
Everything worked until I put in the validation code


<script type="text/javascript">

function validator(meters) {
var MINNUM = 1;
var MAXNUM = 100000;
meters = meters *1; // make meters a number
if ((isNaN(meters)) || (meters < MINNUM) || (meters > MAXNUM)) {
alert("Invalid value entered. Must be a number between 1 & 1000000.");
return false;
};
}

validator(-1); // a number out of range
validator("xyz"); // a string

</script>

var report = function(meters,kilometers)
{
document.getElementById("result").innerHTML = //"result" gets sent to the HTML page where it is being asked for
meters + " meters are equal to " + kilometers + " kilometers";
//is just the text that will show up on the monitor. meters + is what the user typed in. The space after the quotations will insert what was typed in by the user then the text shows up (meters are equal to). + kilometers + inserts the caculation below. The space after the quotations will insert what was caculated. Then the text shows up (kilometers).
};

document.getElementById("m_to_k").onclick = function() // after the user types in the digits the user will click on the button of choice which will preform the caculation below.
{
var meters = document.getElementById("distance").value; //meters will be equal to what the user typed in and be sent to report
var kilometers = (meters *.001); //kilometers will be equal to the caculation in parenthises and will send it to report

report(meters, kilometers); //this report has the information of the digits that were entered (meters) plus the caculation (kilometers) that will be grabbed by the HTL page to be displayed.
};

var report2 = function(meters,inches)
{
document.getElementById("result").innerHTML =
meters + " meters are equal to " + inches + " inches";
};
document.getElementById("m_to_i").onclick = function()
{
var meters = document.getElementById("distance").value;
var inches = (meters * 39.37);

report2(meters, inches);
};

var report3 = function(meters,feet)
{
document.getElementById("result").innerHTML =
meters + " meters are equal to " + feet + " feet";
};
document.getElementById("m_to_f").onclick = function()
{
var meters = document.getElementById("distance").value;
var feet = (meters * 3.281);

report3(meters, feet);
};

Philip M
11-30-2012, 02:09 PM
I removed my validation and inserted your validation and it does not work

Well, it works for me, and it will work for you if you test it. The fault, dear Brutus, lies not in the stars ...

Perhaps </script>
is the problem.



var please = false;
var thanks = false;
if (!please && !thanks) {
var interestLost = true;
var moreHelp = 0;
}

msNewbie
11-30-2012, 04:11 PM
I am not ungrateful I am just so tired and I am sitting here in class on break right now trying to keep my eyes open.
I will see what is wrong.
YES, THANK YOU for your time & consideration in this matter!

AndrewGSW
11-30-2012, 04:58 PM
</script> <<< this is finishing the script

var report = function(meters,kilometers) <<< it should occur at the end of your code



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum