Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validation

Status
Not open for further replies.

unreal1969

Programmer
Dec 7, 2003
9
0
0
CA
Hi ther I'm trying to validate some text boxes according to state of checkboxes.

So of the start all text boxes start off as disabled now if a checkbox is clicked then the textbox is enabled and a value must be entered. On form submit I need to valiadte that at least one checkbox is clicked and the corresponding textbox has a value. But I'm having a litle bit of a hard time with this, can anybody help me.
I keep getting this error "'checked' is null or not an object"

here is my code

function checkWholeForm( frm )
{
var anyChecked = false;
theCount = parseInt( frm.count.value )
for ( var i = 0; i <= theCount; ++i )
{
var cb = frm.elements[&quot;enbl_&quot; + i];
if (cb.checked)
{
anyChecked = true;
var py = frm.elements[&quot;payamount_&quot; + i];
var amt = parseFloat( py.value );
if ( py.value == &quot;&quot; || isNaN(amt) )
{
alert(&quot;You didn't enter a valid payment amount in one of your clients&quot;);
return false;
}
}
}
if ( ! anyChecked )
{
alert(&quot;You must check at least one of the boxes.&quot;);
}
return anyChecked;
}


<form action&quot; method=&quot;post&quot; name=&quot;payment&quot; onSubmit=&quot;return checkWholeForm(this);&quot;>


<%for cnum = 0 to ubound(Arr_Clients,2)

<tr bgcolor=&quot;<%=bgcolor%>&quot;>
<td align=&quot;center&quot;><p class=&quot;medtext&quot;><%=Arr_Clients(2,cnum)%></p></td>
<td align=&quot;center&quot;><p class=&quot;medtext&quot;><%=Arr_Clients(3,cnum)%></p></td>
<td align=&quot;center&quot;><p class=&quot;medtext&quot;><%=Arr_Clients(11,cnum)%></p></td>
<td align=&quot;center&quot;><p class=&quot;medtext&quot;><%=Arr_Clients(12,cnum)%></p></td>
<td align=&quot;center&quot;><p class=&quot;medtext&quot;><%=Arr_Clients(13,cnum)%></p></td>
<td align=&quot;center&quot;><input name=&quot;enbl_<%=cnum%>&quot; onClick=&quot;enable(this,<%=cnum%>);&quot; type=&quot;checkbox&quot; > </td>
<td align=&quot;center&quot;><input name=&quot;payamount_<%=cnum%>&quot; readonly onBlur=&quot;calc(this.value);&quot; type=&quot;text&quot; size=&quot;8&quot; ></td>
</tr>
<input type=&quot;hidden&quot; value=&quot;<%=Arr_Clients(0,cnum)%>&quot; name=&quot;userid&quot;>

<%next%>

<input type=&quot;hidden&quot; value=&quot;<%=cnum%>&quot; name=&quot;count&quot;>

</form>
 
Try
Code:
if(cb.type==&quot;checkbox&quot; && cb.checked)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top