0

Why the following code has the error: 'document.mainform.unknownHw' is null or not an object?

function setUnknownHw(unknownHw)
{
document.mainform.unknownHw.checked = unknownHw;
}


<div class="special">
<form name="mainform" id="mainform" action="display.htm" method="post">
<br><br><input type="checkbox" name="unknownHw" onClick="setdbUnknownHw(this)">Unknown Hw
<input type="submit" value="Apply" onClick="setdbRowsPerPage()"><br>
</form>
</div>

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by almostbob
0

Albert,

It works fine in IE6, FF and Opera.

I can only guess that document.mainform.unknownHw doesn't exist or is not in scope at the point where you call setUnknownHw .

Airshow

0

dom convention refers to id, (in the html scrap below the input has been given an id to make the javascript conventionally valid)
name is not a singleton,
every option in a radio button set has the same name,
but each id can only refer to a single element

<div class="special"> 
<form name="mainform" id="mainform" action="display.htm" method="post"> 
<br>
<br>
<input type="checkbox" name="unknownHw" id="unknownHw" onClick="setdbUnknownHw(this)">
<label for="unknownHw"> Unknown Hw</label>
<input type="submit" value="Apply" onClick="setdbRowsPerPage()">
<br> 
</form> 
</div>

<label> tag creates clickable names for checkboxes, the standard operation everyone seems to expect

the javascript is unusual,
checked has only possible values nul or "checked", and is not usually set programatically onclick,
default handling does that,
what are you trying to accomplish

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.