Click to See Complete Forum and Search --> : Validation of text fields
tuanyong
08-25-2003, 11:03 PM
Could anyone please help me to check those codes and correct come mistakes if possible thanks ...
After testing it, it can't display a dialog box for validation..
<script type="text/javascript">
function validateForm ()
{
if(document.program.date.value =="")
{
alert("Please enter the date of appointment.");
return false;
}
else if(document.program.day.value =="")
{
alert("Please enter the day of appointment.");
return false;
}
else if(document.program.sales_am.value =="")
{
alert("Please enter the name of sales AM.");
return false;
}
else if(document.program.brand.value =="")
{
alert("Please enter the brand of your product.");
return false;
}
else if(document.program.customer.value =="")
{
alert("Please enter the customer name or company.");
return false;
}
else if(document.program.service_req.value =="")
{
alert("Please enter the service requested.");
return false;
}
else if(document.program.time_start.value ==""))
{
alert("Please enter the start time of the appointment!");
return false;
}
else if(isNaN(document.program.no_of_hrs.value ==""))
{
alert("Please enter only digits in the duration of the appointment!");
return false;
}
else
alert("Your request is being processed.Thank you.");
return true;
}
</script>
<form name="program" method="POST" action="bookingSystem.asp" onSubmit="return validateForm();">
Jupac
08-25-2003, 11:32 PM
use something like this
form1.name.value.length == "";
tuanyong
08-26-2003, 12:30 AM
form1.name.value.length == "";
tried using that but the results seems to be the same ..
any other ideas ? or you need the whole source?
Charles
08-26-2003, 05:29 AM
Please post the URL. I suspect that there is a JavaScript error somewhere else on the page.
You might want to use a regexp to also check if the field contains only blank spaces. Try this (http://www.infinitypages.com/research/formvalidation.htm) script, if you need to validate all your form fileds, or this (http://www.infinitypages.com/research/formvalidation_2.htm) one, if you want to be able to specify which fields to validate.
tuanyong
08-26-2003, 10:23 AM
erm .. this page is not published yet ... so i will paste the whole source for you .. thank you very much for helping ..
<html>
<head>
<title>Automated Scheduling Program</title>
</head>
function validateForm ()
{
if(program.date.value=="")
{
alert("Date is required.");
return false;
}
else if(program.day.value=="")
{
alert("Day is required.");
return false;
}
else if(program.sales_am.value=="")
{
alert("Please enter the name of Sales AM.");
return false;
}
else if(program.brand.value=="")
{
alert("Please enter the brand of your product.");
return false;
}
else if(program.customer.value=="")
{
alert("Please enter the customer name or company.");
return false;
}
else if(program.service_req.value=="")
{
alert("Please enter the service requested.");
return false;
}
else if(isNaN(program.no_of_hrs.value==""))
{
alert("Please enter only digits in the duration of the appointment!");
return false;
}
else
alert("Your request is being processed. Thank You.")
return true;
</script>
<body>
<p align="left"><font size="4" color="#008000">Appointment schedule support for the month of September 2003</font></p>
<b>
<form name="program" method="POST" action="bookingSystem.asp "onSubmit="return validateForm();">
<table border="0" width="100%" cellspacing="8">
<tr>
<td width="21%"><b>
<font color="black">Date :</font>
</b></td>
<td width="79%"><b>
<select size="1" name="date" style="border: 1 solid #0099FF">
<option></option>
<option>1 Aug 2003</option>
<option>2 Aug 2003</option>
<option>3 Aug 2003</option>
<option>4 Aug 2003</option>
<option>5 Aug 2003</option>
<option>6 Aug 2003</option>
<option>7 Aug 2003</option>
<option>8 Aug 2003</option>
<option>9 Aug 2003</option>
<option>10 Aug 2003</option>
<option>11 Aug 2003</option>
<option>12 Aug 2003</option>
<option>13 Aug 2003</option>
<option>14 Aug 2003</option>
<option>15 Aug 2003</option>
<option>16 Aug 2003</option>
<option>17 Aug 2003</option>
<option>18 Aug 2003</option>
<option>19 Aug 2003</option>
<option>20 Aug 2003</option>
<option>21 Aug 2003</option>
<option>22 Aug 2003</option>
<option>23 Aug 2003</option>
<option>24 Aug 2003</option>
<option>25 Aug 2003</option>
<option>26 Aug 2003</option>
<option>27 Aug 2003</option>
<option>28 Aug 2003</option>
<option>29 Aug 2003</option>
<option>30 Aug 2003</option>
<option>31 Aug 2003</option>
</select> </b></td>
</tr>
<tr>
<td width="21%"><b>
<font color="black">Day :</font>
</b></td>
<td width="79%"><b>
<select size="1" name="day" style="border: 1 solid #0099FF">
<option></option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
<option>Sunday</option>
</select> </b></td>
</tr>
<tr>
<td width="21%"><b>
<font color="black">Sales AM :</font>
</b></td>
<td width="79%"><b>
<select size="1" name="sales_am" style="border: 1 solid #0099FF">
<option></option>
<option>John Tan</option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select> </b></td>
</tr>
<tr>
<td width="21%"><b>
<font color="black">Brand :</font>
</b></td>
<td width="79%"><b><select size="1" name="brand" style="border: 1 solid #0099FF">
<option></option>
<option>Avaya</option>
<option>Ericsson</option>
<option>Nortel</option>
<option>IVR</option>
<option>Cisco</option>
<option>Miscellaneous</option>
</select></b></td>
</tr>
<tr>
<td width="21%"><b>Customer : </b></td>
<td width="79%"><b><input type="text" name="customer" size="30" style="border: 1 solid #0099FF"></b></td>
</tr>
<tr>
<td width="21%"><b>
<p style="margin-top: 0; margin-bottom: 0">Service requested :</b></p></td>
<td width="79%"><b>
<input type="text" name="service_req" size="55" style="border: 1 solid #0099FF"></b></td>
</tr>
<tr>
<td width="21%"><b>Time start :</b></td>
<td width="79%"><b><input type="text" name="time_start" size="11" style="border: 1 solid #0099FF"></b></td>
</tr>
<tr>
<td width="21%"><b>
<p style="margin-top: 0; margin-bottom: 0">No of hours : </b></p></td>
<td width="79%"><b>
<input type="text" name="no_of_hrs" size="7" style="border: 1 solid #0099FF"></b></td>
</tr>
<tr>
<td width="21%"><b>Remarks :</b></td>
<td width="79%"><b><input type="text" name="remarks" size="70" style="border: 1 solid #0099FF"></b></td>
</tr>
<tr>
<td width="21%"><b>Attachments :</b></td>
<td width="79%"><input type="file" value="Browse" name="B3" style="border: 1 solid #0099FF"> </td>
</tr>
<tr>
<td width="21%"></td>
<td width="79%"><b><input type=button value="Attach Files" class=abutton onclick="BeginAttach()" style="border: 1 solid #0099FF"></b>
<input type=button value="Cancel" class=fbutton onclick="Done()" style="border: 1 solid #0099FF">
</td>
</tr>
</table>
<p align="left"><input type="submit" value="Submit" name="B1" style="border: 1 solid #0099FF">
<input type="reset" value="Reset" name="B2" style="border: 1 solid #0099FF"></p>
</form>
</body>
</html>
AdamBrill
08-26-2003, 10:31 AM
Try this instead of the current script at the top of the page:<script type="text/javascript">
function validateForm (){
if(program.date.options[program.date.options.selectedIndex].innerHTML==""){
alert("Date is required.");
return false;
}else if(program.day.options[program.day.options.selectedIndex].innerHTML==""){
alert("Day is required.");
return false;
}else if(program.sales_am.options[program.sales_am.options.selectedIndex].innerHTML==""){
alert("Please enter the name of Sales AM.");
return false;
}else if(program.brand.options[program.brand.options.selectedIndex].innerHTML==""){
alert("Please enter the brand of your product.");
return false;
}else if(program.customer.value==""){
alert("Please enter the customer name or company.");
return false;
}else if(program.service_req.value==""){
alert("Please enter the service requested.");
return false;
}else if(isNaN(program.no_of_hrs.value=="")){
alert("Please enter only digits in the duration of the appointment!");
return false;
}else{
alert("Your request is being processed. Thank You.")
return true;
}
}
</script> I hope that helps! :)
tuanyong
08-26-2003, 10:39 AM
it works terrificly ... thanks pal ...
AdamBrill
08-26-2003, 10:44 AM
No problem. I'm glad to help. :)