Javascript validation problem
Posted: Thu Jul 14, 2005 3:43 am
On submission of the form, I call the function 'validateForm' which is defined above. The problem is, I try to assign the form values to variables but I dont get anything if I try to display the variables.
<script language="javascript">
<!--
function validateForm(form){
var valid = 1;//initializing form to be valid
alert ("I am inside javascript:");
//getting field values from the form
alert (form.txtName.value);
var name = form.txtName.value;
alert (name);
var company = form.txtCompany.value;
var phone = form.txtTelephone.value;
var email = form.txtEmail.value;
var when = form.txtWhen.value;
var msg = "";
alert (name);
alert (company);
if (name == ""){
msg = msg + ">>Please enter a valid name\n";
valid = 0;
}
if (company == ""){
msg = msg + ">>Please enter your company name!!!\n";
valid = 0;
}
if (phone == ""){
msg = msg + ">>Please enter a valid phone number!!!\n";
valid = 0;
}
if (email == ""){
msg = msg + ">>Please enter a valid email address!!!\n";
valid = 0;
}
if (when == ""){
msg = msg + ">>Please enter when do you want us to call!!!\n";
valid = 0;
}
if (msg == 0){
alert (msg);
}
if (valid == 0){
return "false";
}else{
return "true";
}
}
//-->
</script>
<body>
<table width="700" class = 'bordersOnly' cellspacing="0" style="margin-top:10px; background-color:#000099; color:#FFFFFF">
<tr style="background-color:#999999; "><td></td><td class="Lalign"><h4>Omnisoft - Call Me Back</h4></td></tr>
<tr><td><?php echo $msg; ?></td></tr>
<form name="frmCallBack" method="get" action="" onsubmit="javascript:return validateForm(this)">
For example, I have got five alerts at the first few lines of the function.
It displays the first three alerts but it doesnot display the next two alerts which come next to each other.
they are, alert (name);, alert (company);
It doesnt return true, even then the form submits. You can see the form in action at:
http://raghavan.allhyper.com/callMeBack.php