im4god
06-30-2007, 06:12 AM
Hello,
I am new here and also new to java script and html. I wrote a form and it has java script to check if certain fields in form are filled. However, there's a field which ask the user to select the arrival time with <select name="cararrivaltime">...
This runs ok in firefox and netscape but when I run it in IE 7, it says i haven't select the arrival time.
Can anyone tell me what's wrong and how to correct this please?
Thank you very much.
Elton.
My codes (cut and pasted related lines only)
<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function get_radio_value()
{
for (var i=0; i < document.form.transportmode.length; i++)
{
if (document.form.transportmode[i].checked)
{
var rad_val = document.form.transportmode[i].value;
}
}
}
//-->
</SCRIPT>
<body style="background-color: rgb(227, 227, 236);">
<script type="text/javascript">
function checkForm(form)
{
msg = "";
for (var i=0; i < document.form.transportmode.length; i++)
{
if (document.form.transportmode[i].checked)
{
var rad_val = document.form.transportmode[i].value;
if(rad_val == "air" || rad_val == "car")
{
alert("- Your are coming to Christchurch by " + rad_val + ".");
}
if(rad_val == "local")
{
alert("- You are " + rad_val + " saint.");
}
}
}
if(rad_val == "air")
{
if(!form.arrivaldate.value)
{
msg += "- Your arrivaldate is required\n";
}
if(!form.arrivalflightnumber.value)
{
msg += "- Your arrival flight number is required\n";
}
if(!form.departuredate.value)
{
msg += "- Your departure date is required\n";
}
if(!form.departureflightnumber.value)
{
msg += "- Your departure flight number is required\n";
}
if(msg != "")
{
alert(msg);
return false;
}
}
if(rad_val == "car")
{
if(!form.cararrivaldate.value)
{
msg += "- Your arrivaldate is required\n";
}
if(!form.cararrivaltime.value)
{
msg += "- Your arrival time is required\n";
}
if(msg != "")
{
alert(msg);
return false;
}
}
}
</script>
<form id="form" name="form" method="post" action="form.php" onsubmit="return checkForm(this)" onSubmit="return defaultagree(this)">
<table>
<tr>
<td>
<b>* Arrival Time (approx):</b><br><select name="cararrivaltime"><option></option><option>00:00</option><option>01:00</option><option>02:00</option><option>03:00</option><option>04:00</option><option>05:00</option><option>06:00</option><option>07:00</option><option>08:00</option><option>09:00</option><option>10:00</option><option>11:00</option><option>12:00</option><option>13:00</option><option>14:00</option><option>15:00</option><option>16:00</option><option>17:00</option><option>18:00</option><option>19:00</option><option>20:00</option><option>21:00</option><option>22:00</option><option>23:00</option></select></td>
</tr>
</body>
</html>
I am new here and also new to java script and html. I wrote a form and it has java script to check if certain fields in form are filled. However, there's a field which ask the user to select the arrival time with <select name="cararrivaltime">...
This runs ok in firefox and netscape but when I run it in IE 7, it says i haven't select the arrival time.
Can anyone tell me what's wrong and how to correct this please?
Thank you very much.
Elton.
My codes (cut and pasted related lines only)
<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function get_radio_value()
{
for (var i=0; i < document.form.transportmode.length; i++)
{
if (document.form.transportmode[i].checked)
{
var rad_val = document.form.transportmode[i].value;
}
}
}
//-->
</SCRIPT>
<body style="background-color: rgb(227, 227, 236);">
<script type="text/javascript">
function checkForm(form)
{
msg = "";
for (var i=0; i < document.form.transportmode.length; i++)
{
if (document.form.transportmode[i].checked)
{
var rad_val = document.form.transportmode[i].value;
if(rad_val == "air" || rad_val == "car")
{
alert("- Your are coming to Christchurch by " + rad_val + ".");
}
if(rad_val == "local")
{
alert("- You are " + rad_val + " saint.");
}
}
}
if(rad_val == "air")
{
if(!form.arrivaldate.value)
{
msg += "- Your arrivaldate is required\n";
}
if(!form.arrivalflightnumber.value)
{
msg += "- Your arrival flight number is required\n";
}
if(!form.departuredate.value)
{
msg += "- Your departure date is required\n";
}
if(!form.departureflightnumber.value)
{
msg += "- Your departure flight number is required\n";
}
if(msg != "")
{
alert(msg);
return false;
}
}
if(rad_val == "car")
{
if(!form.cararrivaldate.value)
{
msg += "- Your arrivaldate is required\n";
}
if(!form.cararrivaltime.value)
{
msg += "- Your arrival time is required\n";
}
if(msg != "")
{
alert(msg);
return false;
}
}
}
</script>
<form id="form" name="form" method="post" action="form.php" onsubmit="return checkForm(this)" onSubmit="return defaultagree(this)">
<table>
<tr>
<td>
<b>* Arrival Time (approx):</b><br><select name="cararrivaltime"><option></option><option>00:00</option><option>01:00</option><option>02:00</option><option>03:00</option><option>04:00</option><option>05:00</option><option>06:00</option><option>07:00</option><option>08:00</option><option>09:00</option><option>10:00</option><option>11:00</option><option>12:00</option><option>13:00</option><option>14:00</option><option>15:00</option><option>16:00</option><option>17:00</option><option>18:00</option><option>19:00</option><option>20:00</option><option>21:00</option><option>22:00</option><option>23:00</option></select></td>
</tr>
</body>
</html>