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

checkbox with checked=true

Status
Not open for further replies.

IlseDC

Programmer
Mar 24, 2003
49
BE
In my HTML document I have 3 checkboxes:
<INPUT type="checkbox" name="Items" id="A"/>
<INPUT type="checkbox" name="Items" id="B"/>
<INPUT type="checkbox" name="Items" id="C"/>

When I do the following script the result is 3.
alert (mydocument.forms["myForm"].Items.length);


When I change the HTML with 2 checked checkboxes:
<INPUT type="checkbox" name="Items" id="A" checked="true"/>
<INPUT type="checkbox" name="Items" id="B" checked="true"/>
<INPUT type="checkbox" name="Items" id="C"/>

The result of the following script is 1 instead of 3.
alert (mydocument.forms["myForm"].Items.length);

Does anyone know why I get only the unchecked item with mydocument.forms["myForm"].Items?

Thanks.
Ilse

 
Technically it should be:
Code:
<input type="checkbox" name="Items" id="A" checked="checked" />
[ul]
[li]XHTML element names must be in lower case (I'm assuming you're using XHTML because of the trailing / in the tag).[/li]
[li]You need to put a space before the [tt]/>[/tt] so as not to confuse old browsers.[/li]
[li]Attributes that didn't need a value in HTML have to be given a value equal to their own name in XHTML: [tt]checked="checked"[/tt], [tt]selected="selected"[/tt], etc.[/li]
[/ul]

None of the above explains your Javascript results, though.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
There was an error in the naming of my checkboxes.
Thanks for your advice!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top