If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

JavaScript Validation

What am I doing wrong?
The program works until I try to add the validation.
BTW there are more functions beside m_to_k

Code:

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.
};

still up all night long

Originally Posted by refreezed

You're missing curly brackets around your validator() function.

I am still up trying to get this.
Yes, I did see that and corrected it.
I should have gotten back on the forum.
When I type in a letter, less that 1 or more than 1000000 I get this: meters equals NaNa kilometers you have traveled
instead of this: Invalid digit entered. Must be between 1 & 1000000.

First off your validator function is missing its set of curly braces, as refreezed mentioned secondly you cannot assign a logical operator to a variable that is to say your variable MIMIMUM cant equal less than 1 (<1) and you MAXIMUM cant equal greater than 1000000 (>1000000). I wouldn’t use a while loop either a simple if statement would work, and lastly you return “result” but result is not defined at least not within the scope of your validator function.

Because you have just posted a fragment of your code it is difficult to see exactly what is wrong with it can you post the all the code for the page? This would help greatly

Thank you ever so much!

After I got a second wind today and looked at you code I realized what was going on. If you were here right now I would hug you! ( )
I wound up splitting the code up into different sheets because of the way I wanted to present it and it looks fantastic with all the graphics and HTML stuff I threw in. YOU are a life saver. Thank you ever so much. One more project and I am done for the semester - THANK GOD!!! and that YOU too!