Click to See Complete Forum and Search --> : Passing Variables


bfausti
10-15-2003, 11:35 PM
I am fairly new to javascript and have a little problem. Here's my code:

function disElement(element1,element2) {
el = document.frmFD.element1;
for ( i=0; i < el.length; i++ ) {
if ( el[i].checked ) {
if(el[i].value == "Yes"){
document.frmFD.element2.disabled = false;
}
if(el[i].value == "No"){
document.frmFD.element2.disabled = true;
}
if(el[i].value == "Unsure"){
document.frmFD.element2.disabled = true;
}

}
}
}

</script>

I have a form with 3 radio buttons and a input box (text box) i am trying to disable or enable this box judged on what radio button the user clicks. My problem is I am trying to make this function as generic as possible so I can use it else where (As good programmers should do:)) But it doesn't seem to be working.

Can anyone tell me what is wrong with my code. The error is "el.length is null or not an object."

Khalid Ali
10-16-2003, 12:22 AM
what is element1?
The way your code is written it looks like it should be a radio group array..is it?

post you r html code here

bfausti
10-16-2003, 02:03 AM
My html code is:

....
<tr>
<td class="td-details1" colspan="2" bgcolor="#F5F5F5">
Was there an RVA?</td>
</tr>
<tr>
<td class="td-details1">Yes</td>
<td class="td-details2">
<input type="radio" name="rva" value="Yes" onclick="disRVA()"></td>
</tr>
<tr>
<td class="td-details1">(Specify message)</td>
<td class="td-details2">
<input type="text" name="rvaMessage" size="40" maxlength="255" disabled></td>
</tr>
<tr>
<td class="td-details1">No</td>
<td class="td-details2">
<input type="radio" name="rva" value="No" onclick="disRVA()" checked></td>
</tr>
<tr>
<td class="td-details1">Unsure</td>
<td class="td-details2">
<input type="radio" name="rva" value="Unsure" onclick="disRVA()"></td>
</tr>

....

Khalid Ali
10-16-2003, 02:15 AM
Following code snippet will work


<form id="aForm" action="" onsubmit="" method="post" enctype="text/plain">
<table>
<tr>
<td class="td-details1" colspan="2" bgcolor="#F5F5F5">
Was there an RVA?</td>
</tr>
<tr>
<td class="td-details1">Yes</td>
<td class="td-details2">
<input type="radio" name="rva" value="Yes" onclick="disRVA(this.value,this.form.rvaMessage)"></td>
</tr>
<tr>
<td class="td-details1">(Specify message)</td>
<td class="td-details2">
<input type="text" name="rvaMessage" size="40" maxlength="255" readonly="readonly"></td>
</tr>
<tr>
<td class="td-details1">No</td>
<td class="td-details2">
<input type="radio" name="rva" value="No" onclick="disRVA(this.value,this.form.rvaMessage)" checked></td>
</tr>
<tr>
<td class="td-details1">Unsure</td>
<td class="td-details2">
<input type="radio" name="rva" value="Unsure" onclick="disRVA(this.value,this.form.rvaMessage)"></td>
</tr>
</table>
</form>
<script type="text/javascript">
function disRVA(value,textField){
if(value=="Yes"){
textField.readOnly = false;
}else if(value=="No"){
textField.readOnly = true;
}else if(value=="Unsure"){
textField.readOnly = true;
}
}
</script>

bfausti
10-16-2003, 07:41 PM
Thanks alot that worked just great!

Khalid Ali
10-16-2003, 11:20 PM
:D
my pleasure....