sorry for asking this non-php relates question as I don't know somewhere else to ask. This is a JS form validator, In my code here:
the issu is that
1) when I submit evrythin blank countries list disapear.
and
2) tos check with two passwords comparison if statements don't work properly. What is my mistake there?
The code is:
<html>
<head>
<title>Registration Form Sample</title>
<style type="text/css">
.warning {
color: #AA0000;
}
</style>
<script language="javascript">
function submitform(){
var message = "";
if (window.document.userinfo.first_name.value.length <= 1){
document.getElementById("fname").innerHTML = "-->";
window.document.userinfo.first_name.focus();
var error = true;
} else {
document.getElementById("fname").innerHTML = "";
}
if (window.document.userinfo.last_name.value.length <= 1){
document.getElementById("lname").innerHTML = "-->";
window.document.userinfo.last_name.focus();
var error = true;
} else {
document.getElementById("lname").innerHTML = "";
}
if (window.document.userinfo.company.value.length <= 1){
document.getElementById("company").innerHTML = "-->";
window.document.userinfo.company.focus();
var error = true;
} else {
document.getElementById("company").innerHTML = "";
}
if (window.document.userinfo.addr_01.value.length <= 1){
document.getElementById("addr01").innerHTML = "-->";
window.document.userinfo.addr_01.focus();
var error = true;
} else {
document.getElementById("addr01").innerHTML = "";
}
if (window.document.userinfo.city.value.length <= 1){
document.getElementById("city").innerHTML = "-->";
window.document.userinfo.city.focus();
var error = true;
} else {
document.getElementById("city").innerHTML = "";
}
if (window.document.userinfo.state.value.length <= 1){
document.getElementById("state").innerHTML = "-->";
window.document.userinfo.state.focus();
var error = true;
} else {
document.getElementById("state").innerHTML = "";
}
if (window.document.userinfo.country.value.length <= 1){
document.getElementById("country").innerHTML = "-->";
window.document.userinfo.country.focus();
var error = true;
} else {
document.getElementById("country").innerHTML = "";
}
if (window.document.userinfo.zip.value.length <= 1){
document.getElementById("zip").innerHTML = "-->";
window.document.userinfo.zip.focus();
var error = true;
} else {
document.getElementById("zip").innerHTML = "";
}
if (window.document.userinfo.phone.value.length <= 8){
document.getElementById("phone").innerHTML = "-->";
window.document.userinfo.phone.focus();
var error = true;
} else {
document.getElementById("phone").innerHTML = "";
}
if (window.document.userinfo.username.value.length <= 8){
document.getElementById("username").innerHTML = "-->";
window.document.userinfo.username.focus();
var error = true;
} else {
document.getElementById("username").innerHTML = "";
}
if (window.document.userinfo.pswrd.value.length <= 8){
document.getElementById("pswrd").innerHTML = "-->";
window.document.userinfo.pswrd.focus();
var error = true;
} else {
document.getElementById("pswrd").innerHTML = "";
}
if (!window.document.userinfo.tos.checked){
message += "Tos not checked.";
document.getElementById("Error").innerHTML = message;
window.document.userinfo.tos.focus();
var error = true;
} else {
document.getElementById("Error").innerHTML = "";
}
if (window.document.userinfo.pswrd.value != window.document.userinfo.pswrd_1.value){
message += "Passwords are not egal.";
document.getElementById("Error").innerHTML = message;
window.document.userinfo.pswrd.focus();
var error = true;
} else {
document.getElementById("Error").innerHTML = "";
}
if (error == true) {
return false;
} else {
return true;
}
}
</script>
</head>
<body>
<form name="userinfo" action="" method="POST" onSubmit="return submitform();">
<table cellspacing="1" class="bodyTable">
<tr>
<td colspan="2" class="table_header"><div class="warning" id="Error"></div> Personal Information</td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="fname"></div> First Name: </td>
<td class="menu_title"><input type="text" size="30" name="first_name" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="lname"></div> Last Name: </td>
<td class="menu_title"><input type="text" size="30" name="last_name" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="company"></div> Company: </td>
<td class="menu_title"><input type="text" size="30" name="company" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="addr01"></div> Address 1: </td>
<td class="menu_title"><input type="text" size="30" name="addr_01" value=""></td>
</tr>
<tr>
<td class="menu_text">Address 2: </td>
<td class="menu_title"><input type="text" size="30" name="addr_02" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="city"></div> City: </td>
<td class="menu_title"><input type="text" size="30" name="city" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="state"></div> State: </td>
<td class="menu_title"><input type="text" size="30" name="state" value=""></td>
</tr>
<tr>
<td class="menu_text">Country: </td>
<td class="menu_title">
<select name="country">
<option value="United States">United States</option>
<option value="Canada">Canada</option>
</select>
</td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="zip"></div> Zip Code: </td>
<td class="menu_title"><input type="text" size="30" name="zip" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="phone"></div> Phone: </td>
<td class="menu_title"><input type="text" size="30" name="phone" value=""></td>
</tr>
<tr>
<td class="menu_text">Fax: </td>
<td class="menu_title"><input type="text" size="30" name="fax" value=""></td>
</tr>
<tr>
<td colspan="2" class="no_border"> </td>
</tr>
<tr>
<td colspan="2" class="table_header">User Account Information</td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="username"></div> Username: </td>
<td class="menu_title"><input type="text" name="username" size="30" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="email"></div> Email: </td>
<td class="menu_title"><input type="text" name="email" size="30" value=""></td>
</tr>
<tr>
<td class="menu_text"><div class="warning" id="pswrd"></div> Password: </td>
<td class="menu_title"><input type="password" name="pswrd" size="30" value=""></td>
</tr>
<tr>
<td class="menu_text">Confirm Password: </td>
<td class="menu_title"><input type="password" name="pswrd_1" size="30" value=""></td>
</tr>
<tr>
<td colspan="2" class="no_border"><input type="checkbox" name="tos" value="1"> I accept and will follow all <a href="tos.php" target="_blank">Terms of Service</a></td>
</tr>
<tr>
<td colspan="2" class="no_border">
<input type="hidden" name="level" value="1">
<input type="hidden" name="id" value="">
<br><input type="submit" name="submit" value=" Save " class="ButtonSubmit">
</td>
</tr>
</table>
</form>
</body>
</html>