I am trying to verify the contents of a form before submitting it. Basically, I am trying to work with numbers in the form and ensure that they are in the correct range. The problem is that the JavaScript I'm trying to test thinks that the element passed to it is NaN (I parsed it).
A little work showed that the variable ("size") refers to the "HTMLInputEleMent", which I think is really NaN (although I'm not quite sure what it really is). I think the problem is that onSubmit does not convey what I want it to pass, even if I called the field "size" and I also passed "Size".
I tried putting it in quotes, but that just turns it into a string ...
I am wondering, maybe you canβt pass the variable from WITHIN of the form to the onSubmit field? This is true? If so, how do I do this?
Here is the form:
<form onsubmit="return goodForm(size, day, month, year)" action="http://localhost:8080/pomper_servlet/CostCalc" method="GET"> The day of the month must be entered as a number (ex: 1,22) <input type="text" name="day"><br> The month of the year must be entered as a number (ex: Jan.=1, etc.) <input type="text" name="month"><br> The year must be entered as a 4 digit number (ex: 2008, 2017) <input type="text" name="year"><br> Please Choose a tour-length, in accordance with the chart below: <input type="TEXT" name="length"><br> How many people will be in your group? (No More than 10 allowed!) <input type="text" name="size"><br> Please select a tour:<br> <input type="RADIO" name="tour" value="Gardiner Lake"> Gardiner Lake<br> <input type="RADIO" name="tour" value="Hellroaring Plateau"> Hellroaring Plateau<br> <input type="RADIO" name="tour" value="The Beaten Path"> The Beaten Path<br> <input type="SUBMIT" value="Submit"> </form>
And here is the function, from functions.js:
function goodForm(gSize, day, month, year) { "use strict"; window.alert("goodFrame(): "+gSize); var groupSize1 = parseInt( gSize.replace(/^"|"$/g, ""), 10); window.alert("goodFrame(): "+groupSize1); var sizeInt = parseInt(groupSize1); if(groupSize(sizeInt) && goodDate(day, month, year)){ window.alert("true"); return true; } else{ window.alert("false") return false; }
There are links to other functions there, but they are not related to this, I think. Warnings were / are for debugging purposes ...
Thanks in advance!