Click to See Complete Forum and Search --> : Validate text area & text box when a radio button is clicked


shanuragu
09-04-2003, 01:36 AM
Hi

I have a set of radio buttons , each radio button has a textarea & a text box associated with it.
First I have to validate for radio buttons & the respective text area & a text box (when a radio button is clicked respective text are & text boxes should not be empty).
How can I do this

Radio button & related text area & text boxes are displayed in the web page as follows

<tr>
<td width="75%" valign="top"><input type="radio" name="inv_desc_id" value="<%=rsDetails("inv_desc_id")%>" onclick="document.form.amt.value='<%=rsDetails("invoice_amt")%>'"><textarea rows="2" cols="47" name="inv_desc_<%=rsDetails("inv_desc_id")%>"><%=rsDetails("invoice_desc")%></textarea></td>
<td width="25%" align="right" valign="top" style="padding-right:10px"><input type="text" size="10" name="inv_amt_<%=rsDetails("inv_desc_id")%>" value="<%=objUtils.FormatString(CStr(rsDetails("invoice_amt")), "####0.00")%>"></td>
</tr>

please help

shara

Charles
09-04-2003, 01:53 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
function validate(f){
var i;
for (i=0; i<f.invDescId.length; i++) {if (f.invDescId[i].checked && (!/\S/.test(f['area'+ i].value) || (!/\S/.test(f['text' + i].value)))) {alert('error'); return false}}
}
// -->
</script>
<form action="" onsubmit="return validate(this)">
<p>
<div>
<input type="radio" name="invDescId">
<textarea name="area0"></textarea>
</div>
<div>
<input type="text" name="text0">
</div>
</p>
<p>
<div>
<input type="radio" name="invDescId">
<textarea name="area1"></textarea>
</div>
<div>
<input type="text" name="text1">
</div>
</p>
<div>
<button type="submit">Submit</button>
</div>
</form>

shanuragu
09-04-2003, 05:29 AM
Thank you ... for ur timely help :D

shara