numbers in validation script
Posted: Tue Jan 11, 2011 11:26 am
I Have a form which I use to enter hours and minutes onto a page (configChange.php):
This gives me four boxes for hours and minutes (twice).
I then want to write some javascript to check that the first one is less than the second one.
I have the following javascript:
if you Ignore the section about an email address as that works fine, But the other sectin just fails. I tried putting the 'timesmallSEC' and timelargeSEC' variables into the warning to see what numbers were actually being retunrned and I just get 'NaN' which is apparenlty not a number. But I can't see why this would be, as surely the form should be generating a number.
Code: Select all
<form name="configChange" action="configUpdate.php" method="post" onSubmit="return ValidateForm()">
//email address section added here, which works fine //
CONFIG:</br>
first warning after:
<?php
print "<select name=\"timesmallH\">";
for($a = 0; $a <13; $a++) {
print "<option value=$a>$a</option>";
}
print "</select> Hours";
print "<select name=\"timesmallM\">";
for($a = 0; $a <61; $a++) {
print "<option value=$a>$a</option>";
};
print "</select> Minutes";
?>
</br>
Second warning after:
<?php
print "<select name=\"timelargeH\">";
print "<option Selected=\"selected\" value=\"$timelargeH\">$timelargeH </option>";
for($a = 0; $a <13; $a++) {
print "<option value=$a>$a</option>";
}
print "</select> Hours";
print "<select name=\"timelargeM\">";
print "<option Selected=\"selected\" value=\"$timelargeM\">$timelargeM </option>";
for($a = 0; $a <61; $a++) {
print "<option value=$a>$a</option>";
};
print "</select> Minutes";
?>
</br>
</br>
<input type="Submit" value="Save Changes"/>
</form>
I then want to write some javascript to check that the first one is less than the second one.
I have the following javascript:
Code: Select all
function ValidateForm(){
var emailAddress=document.configChange.emailAddress
var timesmallH=document.configChange.timesmallH
var timesmallM=document.configChange.timesmallM
var timelargeH=document.configChange.timelargeH
var timelargeM=document.configChange.timelargeM
var timesmallSEC = ((timesmallH * 60 * 60) + (timesmallM * 60))
var timelargeSEC = ((timelargeH * 60 * 60) + (timelargeM * 60))
if ((emailAddress.value==null)||(emailAddress.value=="")){
alert("Please Enter an Email Address")
emailAddress.focus()
return false
}
if (timesmallSEC.value > timelargeSEC.value){
alert("warning text goes here")
timesmallH.focus()
return false
}
return true
}