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

Select checkboxes on action.

Status
Not open for further replies.

webamoeba

Programmer
Sep 6, 2006
23
GB
Hi,

I have a dropdown selectbox:

Code:
<select name="units" style="width: 200px;">
    <option value="">ALL</option>
    <option value="">CPT1</option>
    <option value="">CPT2</option>
</select>

And a bunch of checkboxes:

Code:
<label style="width: 60px;"><input type="checkbox" name="unit521" value="unit521" checked="checked" />521</label>
<label style="width: 60px;"><input type="checkbox" name="unit522" value="unit522" checked="checked" />522</label>
<label style="width: 60px;"><input type="checkbox" name="unit524" value="unit524" checked="checked" />524</label>
<label style="width: 60px;"><input type="checkbox" name="unit525" value="unit525" checked="checked" />525</label>
<label style="width: 60px;"><input type="checkbox" name="unit526" value="unit526" checked="checked" />526</label>
<label style="width: 60px;"><input type="checkbox" name="unit527" value="unit527" checked="checked" />527</label>

These are automatically generated by a Perl script. Each item in the dropdown will have a number of checkboxes associated with it.

I want it so as when you select an item from the dropdown it checks the associated chekcboxes, and unchecks those not associated.

I had a quick go but couldn;t seem to get it to work. How can I do this???

Thanks.
 
In your case, i think dropdown item-checked checkbox relationship should be handled in Perl. For checked checkbox, keep the 'checked' attribtue
Code:
<label style="width: 60px;"><input type="checkbox" name="unitXXX" value="unitXXX" checked />XXX</label>
For unchecked checkboxs, remove 'checked' attribute
Code:
<label style="width: 60px;"><input type="checkbox" name="unitYYY" value="unitYYY"/>YYY</label>
 
also to make code valid you need to code it
Code:
checked="checked"
the same as readonly or selected
Code:
readonly="readonly"
selected="selected"
it is good practice to use these checked,selected,readonly attributes in the correct manner.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
hmmm, that's what is already in place. To me it makes no sense. It means you canm select what ever checkboxes you like, but if you select somthing from the dropdownbox it over-rides it... Just seems confusing to me.

Perhaps there would be a better way of doing this without the dropdown??
 
you can fire JS with the onchange attribute on the select and then uncheck all the boxes required dependent on the value of the select list.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top