How to use DOM to check a checkbox

A

ameshkin

I have no idea why this code is not working, but believe that it
should be. I'm still a novice at javascript, and would really
appreciate any help.

The error I'm getting with firebug is:
checkbox1 is null
[Break on this error] checkbox1.checked = true;

<script language="javascript">
function checker() {
var checkbox1 = document.getElementById('sch-1');
checkbox1.checked = true;
var checkbox5 = document.getElementById('sch-5');
checkbox5.checked = true;
var checkbox10 = document.getElementById('sch-10');
checkbox10.checked = true;
}
checker();
</script>

</pre><!--<h1>8 Scholarships Found</h1>
<p><a href="add-scholarship.php" target="_parent">Add Scholarships</
a></p>-->
<table width="70%" border="0" cellspacing="0" cellpadding="0"
id="sch_array">

<td width="7"><input name="sch" id="sch-15" type="checkbox"
value="sadfsadf" style="width:7px;" /></td>
<td width="170"> sadfsadf</td>
<td width="7"><input name="sch" id="sch-14" type="checkbox"
value="sadfsadf" style="width:7px;" /></td>

<td width="170"> sadfsadf</td>
<tr>
<td width="7"><input name="sch" id="sch-13" type="checkbox"
value="sadfsadf" style="width:7px;" /></td>
<td width="170"> sadfsadf</td>

<td width="7"><input name="sch" id="sch-12" type="checkbox"
value="te" style="width:7px;" /></td>
<td width="170"> te</td>

</tr>
<tr>
<td width="7"><input name="sch" id="sch-11" type="checkbox"
value="test2" style="width:7px;" /></td>
<td width="170"> test2</td>

<td width="7"><input name="sch" id="sch-10" type="checkbox"
value="Test Scholar" style="width:7px;" /></td>
<td width="170"> Test Scholar</td>
</tr>
<tr>

<td width="7"><input name="sch" id="sch-5" type="checkbox"
value="Freeman-Asia Scholarship " style="width:7px;" /></td>
<td width="170"> Freeman-Asia Scholarship </td>

<td width="7"><input name="sch" id="sch-1" type="checkbox"
value="GO Scholarship" style="width:7px;" /></td>
<td width="170"> GO Scholarship</td>

</table>
 
A

ameshkin

Thanks man, I had a feeling it was something silly. I keep forgetting
about that little rule. It's working great now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top