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>

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.