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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox disable script problem

Status
Not open for further replies.

casa3311

Programmer
Dec 10, 2002
12
US
This script works in IE but not in Netscape. I get this error message when I click on a radio button:

JavaScript Error: file:/c|/winnt/temp/hs~new.htm, line 52:

form1 is not defined.

JavaScript Error: file:/c|/winnt/temp/hs~new.htm, line 47:

form1 is not defined.

Here's the code:

<html>
<head>
<title>Untitled</title>

</head>
<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;2&quot;>
<tr>
<td><input type=&quot;radio&quot; name=&quot;gr1&quot; value=&quot;Yes&quot; onClick=&quot;Disab(1)&quot;></td>
<td>US History 10</td>
<td><input type=&quot;checkbox&quot; name=&quot;UHist10_01A&quot; value=&quot;Yes&quot; disabled></td>
<td>Section 01A</td>
</tr>
<tr>
<td colspan=&quot;2&quot;> </td>
<td><input type=&quot;checkbox&quot; name=&quot;UHist10_02A&quot; value=&quot;No&quot; disabled></td>
<td>Section 02A</td>
</tr>
<tr>
<td colspan=&quot;2&quot;> </td>
<td><input name=&quot;UHist10_03A&quot; type=&quot;checkbox&quot; disabled id=&quot;UHist10_03A&quot; value=&quot;Yes&quot;></td>
<td>Section 03A</td>
</tr>
<tr><td colspan=&quot;4&quot;> </td></tr>
<tr>
<td><input type=&quot;radio&quot; name=&quot;gr1&quot; value=&quot;No&quot; onClick=&quot;Disab(2)&quot;></td>
<td>US History 11</td>
<td><input type=&quot;checkbox&quot; name=&quot;UHist11_01A&quot; value=&quot;Yes&quot; disabled></td>
<td>Section 01A</td>
</tr>
<tr>
<td colspan=&quot;2&quot;> </td>
<td><input type=&quot;checkbox&quot; name=&quot;UHist11_02A&quot; value=&quot;No&quot; disabled></td>
<td>Section 02A</td>
</tr>
<tr>
<td colspan=&quot;2&quot;> </td>
<td><input name=&quot;UHist11_03A&quot; type=&quot;checkbox&quot; disabled id=&quot;UHist11_03A&quot; value=&quot;No&quot;></td>
<td>Section 03A</td>
</tr>
</table>
</form>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function Disab (val) {
if(val==&quot;1&quot;) {
form1.UHist10_01A.disabled=false;
form1.UHist11_01A.disabled=true;
form1.UHist11_01A.checked=false;
form1.UHist10_02A.disabled=false;
form1.UHist11_02A.disabled=true;
form1.UHist11_02A.checked=false;
form1.UHist10_03A.disabled=false;
form1.UHist11_03A.disabled=true;
form1.UHist11_03A.checked=false;
}
if(val==&quot;2&quot;) {
form1.UHist11_01A.disabled=false;
form1.UHist10_01A.disabled=true;
form1.UHist10_01A.checked=false;
form1.UHist11_02A.disabled=false;
form1.UHist10_02A.disabled=true;
form1.UHist10_02A.checked=false;
form1.UHist11_03A.disabled=false;
form1.UHist10_03A.disabled=true;
form1.UHist10_03A.checked=false;
}
}
</SCRIPT>
</body>
</html>
 
Hi casa3311,

Netscape doesn't forgive you much mistakes;

1) You have 2 times a radiobutton called &quot;gr1&quot; in your form. Rename the second one.

2) Try to avoid underscore in element-names. I read somewhere that not al browsers accept underscores.

I can't test netscape here, but I hope this helps,
Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Give an 'id' to your elements like this

<form name=&quot;form1&quot; id=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>

if you write this : onClick=&quot;Disab(1)&quot; then don't check like this : if (val==&quot;2&quot;) but like this if (val == 2)

Try to use this document.form1.UHist10_01A.disabled=false; instead of form1.UHist10_01A.disabled=false;

I hope it could help you


 
Thanks for the replies. I had already added the document.form1... and that made the javascript error go away, but it still doesn't work in Netscape.

I change the &quot;1&quot;/&quot;2&quot; to 1/2 and that didn't fix the problem either. I think it's going to have to be some Netscape specific code that fixes this since I just read that Netscape does not recognize formname.fieldname.disable. I think I found a site that tells me what to do, I just can't figure out how to integrated it into what already works for IE. This is what I found at
NETSCAPE NAVIGATOR 4.X
Unfortunately, Netscape does not recognize the disabled property. Instead, you must use a variety of techniques to disable the various form elements.

Button, Checkbox, Reset Button, and Submit Button
In Netscape, the button, checkbox, reset button, and the submit button can be disabled using the onclick method. The programmer should replace the else clause in the onclick code below with their default onclick event-handling code (or simply remove the else clause if they do not need to implement an onclick handler).

Checkbox:
<input type=&quot;checkbox&quot; onclick=&quot;if (this.disabled) return false; else alert('clicked')&quot; name=&quot;check1&quot; id=&quot;check1&quot; value=&quot;one&quot;>

As far as the radio buttons go, they HAVE to be named the same thing or the script for the script to work as intended. This is an either or situation. If the user select from the first list, the second list must be cleared and the boxes disabled. So considering that, the radio button is irrelivant since I'm passing everything in the checkbox value that I need for my data processing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top