vineet
11-22-2008, 07:54 AM
hi all
i have a form with two fields that alert combine validations if both fields are empty. But the problem is i m getting a blank alert with nothing written when both fields are filled and submit button is clicked.
this is the code
<script language="javascript">
function validate()
{
var msg="";
if(document.advertise.uname.value=='')
{
msg="Must Enter UserName\n";
document.advertise.uname.focus();
}
if(document.advertise.ucompany.value=='')
{
msg= msg + "Must Enter Company Info\n";
document.advertise.ucompany.focus();
}
alert(msg);
return false;
}
</script>
<body>
<table width="501" border="0" align="center">
<form name="advertise" onSubmit="return validate()">
<tr>
<td width="213" height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><div align="right">Name</div></td>
<td height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"> </td>
<td height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><input name="uname" type="text" class="bodytext" id="uname" size="30" /></td>
</tr>
<tr>
<td height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><div align="right">Company Name</div></td>
<td width="11" height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"> </td>
<td width="263" height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><input name="ucompany" type="text" class="bodytext" id="ucompany" size="30" /></td>
</tr>
<tr>
<td height="50" class="bodytext"><div align="right">
<input name="submit" type="submit" class="style45" id="submit" value="Submit" />
</div></td>
<td class="bodytext"> </td>
<td class="bodytext"></td>
</tr>
</form>
</table>
</body>
i have a form with two fields that alert combine validations if both fields are empty. But the problem is i m getting a blank alert with nothing written when both fields are filled and submit button is clicked.
this is the code
<script language="javascript">
function validate()
{
var msg="";
if(document.advertise.uname.value=='')
{
msg="Must Enter UserName\n";
document.advertise.uname.focus();
}
if(document.advertise.ucompany.value=='')
{
msg= msg + "Must Enter Company Info\n";
document.advertise.ucompany.focus();
}
alert(msg);
return false;
}
</script>
<body>
<table width="501" border="0" align="center">
<form name="advertise" onSubmit="return validate()">
<tr>
<td width="213" height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><div align="right">Name</div></td>
<td height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"> </td>
<td height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><input name="uname" type="text" class="bodytext" id="uname" size="30" /></td>
</tr>
<tr>
<td height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><div align="right">Company Name</div></td>
<td width="11" height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"> </td>
<td width="263" height="30" valign="top" bgcolor="#EFEFEF" class="bodytext"><input name="ucompany" type="text" class="bodytext" id="ucompany" size="30" /></td>
</tr>
<tr>
<td height="50" class="bodytext"><div align="right">
<input name="submit" type="submit" class="style45" id="submit" value="Submit" />
</div></td>
<td class="bodytext"> </td>
<td class="bodytext"></td>
</tr>
</form>
</table>
</body>