...

View Full Version : works in firefox but not ie



ryland22
07-05-2005, 03:43 PM
Can someone tell me why the following works in firefox but not in ie:

<script>
function ValidateForm(form){
var curdate = new Date();
var month = curdate.getMonth();

if(form.numbers.value<=month && form.years.value==2005){
alert('The expiration date you entered has expired. \n \nPlease enter a valid date.');
return false;
}
return true;
}

</script>

<body>
<form action="hotels.htm" method="get" onsubmit="javascript:return ValidateForm(this)">
<select name="numbers">
<option></option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
</select>
<select name="years">
<option></option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>

martin_narg
07-05-2005, 03:50 PM
will post a solution in a sec

ryland22
07-05-2005, 03:53 PM
Still not working.

martin_narg
07-05-2005, 04:07 PM
You forgot to put the value attribute into the option tag mate.



<script>
function ValidateForm(f){
var curdate = new Date();
var month = curdate.getMonth();
if(isNaN(parseInt(f.numbers.value))) {
alert('Please select month');
return false;
}
if( f.years.value.length < 1) {
alert('Please select year');
return false;
}

if(parseInt(f.numbers.value) <= month && parseInt(f.years.value) == 2005) {
alert('The expiration date you entered has expired. \n \nPlease enter a valid date.');
return false;
}
return true;
}

</script>
<form name="frm" action="hotels.htm" method="get" onsubmit="return ValidateForm(this)">
<select name="numbers">
<option></option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
</select>
<select name="years">
<option></option>
<option value="2005">2005</option>
<option value="2005">2006</option>
<option value="2005">2007</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>


Hope this helps

m_n

Burgerking63
07-05-2005, 04:08 PM
EDIT: Ahh, sorry martin, didnt see your post when I started to debug. ;)


You didnt include "values" for your options, so when IE called the select box element on your form, there was no value set for each option, only a read only string denoting the text that appears representing each option. Here is the code that works in both IE and Firefox:

<script>
function ValidateForm(form){
var curdate = new Date();
var month = curdate.getMonth();

if (form.numbers.value <= month && form.years.value == 2005){
alert('The expiration date you entered has expired. \n \nPlease enter a valid date.');
return false; }
else {
return true;}
}
</script>

<body>
<form action="hotels.htm" method="get" onsubmit=" return ValidateForm(this)">
<select name="numbers">
<option></option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
</select>
<select name="years">
<option></option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>

</body>

ryland22
07-05-2005, 04:27 PM
Thanks for the help - I didn't know ie required the values!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum