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

Populate dropdown list w/values checked in checkboxes

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I need to be able to populate a dropdown list with values that are selected (checked) in checkboxes.

Code:
<input type="checkbox" name="usergroup[]" value="<?=$usergroup_name?>">

Each checkbox value is placed in an array (usergroup[]). Is there a way to get the values of checked boxes without submitting the form?

 
Yes. You can use "getElementsByName" to effectively return an array of controls, and then loop through them.

However, you might run into problems because of your illegal naming syntax ("[" and "]" are NOT legal characters for HTML names, so you might want to change them).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Altrhough this is bordering on Javascript rather than plain html. To overcome the bracket problme in elemtn names. )I'm assuming you have PHP somewhere in there) you can use getElementsByID instead. and give each elemtn an ID without the brackets.

BTW, the javascript forum is here: Forum216

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Dan said:
However, you might run into problems because of your illegal naming syntax ("[" and "]" are NOT legal characters for HTML names, so you might want to change them).
Actually, they are valid, as we have discovered at the end of this particular thread: thread434-1221256

They are vital for multiple selections in PHP as well, so one will see them used quite frequently alongside PHP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top