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.
};
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
The entire program runs except for the validation.
Can you please fix this for me?
I am seeing cross-eyed and have to get ready for school and haven't been to bed all night.
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.
};
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);
};
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!
Bookmarks