PDA

View Full Version : Form Validation Question



JoeStone
May 1st, 2003, 06:54 PM
I need help in determining that the first input has a value(not zero or not blank).
My goal is to check every input. I have tried a lot of different things. Please help. Thanks.

<html>

<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<head>

<script type="text/javascript" language="javascript">
function validate(f)
{
var el, e = 0;
while (el = f.elements[e++]) {
if (el.name != document.getElementById('Wcpglist.CPCAID(1)').value) {
var str=!el.value
var id=/(^\d+$)|(^\d+\.\d+$)/
if (id.test(str))
return true;}
else{
alert("The ID must be a Valid Number!")
el.focus();
return false;}
}

}
</script>

</head>

<body>

<table class="section" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>

</tr>
</table>
<table>
</table>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<!-- table above ends at bottom -->
<form method="POST" action="/cgi-bin/WebConnect" onsubmit="return validate(this)" name="CPGList">

<table id="table0" border="1" width="100%" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" style="color: black"><font size="1"><b>Active</b></font></td>
<td align="center" style="color: black"><font size="1"><b>ID</b></font></td>
<td align="center" title="HH:MM AM or PM
Time field must have an AM or a PM entered.
A Colon must separate the HH and MM." style="color: black"><font size="1"><b>Send Start Time</b></font></td>
<td align="center" title="HH:MM AM or PM
Time field must have an AM or a PM entered.
A Colon must separate the HH and MM." style="color: black"><font size="1"><b>Send End Time</b></font></td>
<td align="center" style="color: black"><font size="1"><b>Send Days Range</b></font></td>
</tr>

<tr>

<td align="center">
<select size="1" name="Wcpglst.cpstat(1)">
<option
selected value="Y">Y</option>
<option value="N">N</option>
</select>
</td>
<td align="center">
<input type="text" size="5" name="Wcpglst.CPCAID(1)" maxlength="5" value="106">
</input></td>


<td align="center">
<input type="text" size="8" name="Wcpglst.CPSSTM(1)" maxlength="8" value="07:15 AM"></input>
</td>

<td align="center"><input type="text" size="8" name="Wcpglst.CPSETM(1)" maxlength="8" value="09:30 PM"></input>
</td>

<td align="center"><input type="text" size="4" name="Wcpglst.CPSDRG(1)" maxlength="4" value="2"></input>
<input type="hidden" name="Wcpglst.CDCPID(1)" value="10001">
</td>
</tr>
<tr>


<td align="center">
<select size="1" name="Wcpglst.cpstat(2)">
<option
value="Y">Y</option>
<option value="N">N</option>
</select>
</td>
<td align="center">
<input type="text" size="5" name="Wcpglst.CPCAID(2)" maxlength="5" value="">
</input></td>


<td align="center">
<input type="text" size="8" name="Wcpglst.CPSSTM(2)" maxlength="8" value=""></input>
</td>

<td align="center"><input type="text" size="8" name="Wcpglst.CPSETM(2)" maxlength="8" value=""></input>
</td>

<td align="center"><input type="text" size="4" name="Wcpglst.CPSDRG(2)" maxlength="4" value=""></input>
<input type="hidden" name="Wcpglst.CDCPID(2)" value="10002">
</td>
</tr>
<tr>

<td align="center">
<select size="1" name="Wcpglst.cpstat(16)">
<option
value="Y">Y</option>
<option value="N">N</option>
</select>
</td>
<td align="center">
<input type="text" size="5" name="Wcpglst.CPCAID(16)" maxlength="5" value="">
</input></td>


<td align="center">
<input type="text" size="8" name="Wcpglst.CPSSTM(16)" maxlength="8" value=""></input>
</td>

<td align="center"><input type="text" size="8" name="Wcpglst.CPSETM(16)" maxlength="8" value=""></input>
</td>

<td align="center"><input type="text" size="4" name="Wcpglst.CPSDRG(16)" maxlength="4" value=""></input>
<input type="hidden" name="Wcpglst.CDCPID(16)" value="10016">
</td>
</tr>

</table>
</td>
</tr>

<tr><td align="center">
<input type="reset" value="Reset" title="Pressing this button will reset this page to the original values that were first loaded.">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<a href="javascript:document.CPGList.submit();">
<input type="submit" value="Update"></a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a title="Return to List - No Values Updated!"><input type="button" value="Back" onClick="document.location='/cgi-bin/WebConnect?*DTTwdf=*LOCAL/*libl/WFCAC01/INITLOAD'"></a>

</form>
</td>
</tr>
</table>
</body>
</html>

beetle
May 1st, 2003, 07:25 PM
fValidate (http://www.peterbailey.net/fValidate/)
!!!

I'll even be releasing a new version in a few weeks :thumbsup: