Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the checkbox selected when click the label?

<input type="checkbox"  />  
<label>I agree</label>  

Now when I click "I agree", nothing happens, I'd like to make the checkbox checked, what's the easiest way to do this?

like image 671
wong2 Avatar asked Oct 16 '11 05:10

wong2


People also ask

How can I check if a checkbox is clicked on a label?

You must set an id for your checkbox, then refer it in the for attribute of the label. The id you use must be unique within your html document - basic but often missed!

Can we make label clickable?

Label widgets in Tkinter are used to display text and images. We can link a URL with the label widget to make it clickable. Whenever the label widget is clicked, it will open the attached link in the default browser.

How do I add a checkbox to text?

Click on the exact place in the document where you want to insert a single checkbox. Click on the Insert menu and then on Symbol option. From the list of symbols find the checkbox symbol you want to insert and double click on it.


2 Answers

for and id attributes

<input id="thisinput" type="checkbox"  />  
<label for="thisinput">I agree</label>

http://jsfiddle.net/PNYNR/

like image 151
Steve Robbins Avatar answered Sep 23 '22 20:09

Steve Robbins


As an alternative to what @stevether suggested, you can also wrap the label around the checkbox

<label><input type="checkbox"  /> I agree</label> 

http://jsfiddle.net/WDerc/

like image 35
Dan F Avatar answered Sep 22 '22 20:09

Dan F