Select radio button on shortcut

How to make switches for selection when I click on either of the two labels in front of this switch?

I have code for the switches:

<div class="label_main" style="width:350px"> <div class="label_radio"> <input type="radio" name="group1" id="group1" value="0" <?php if($r0==0) { ?> checked="checked" <?php } ?> /> </div> <div class="label_top"> <label for="group1">First Option </label> </div> <div class="label_desc"> <label for="group1">This is first option </label> </div> </div> </div> <div class="label_main" style="width:350px"> <div class="label_radio"> <input type="radio" name="group1" id="group1" value="1" <?php if($r0==1) { ?> checked="checked" <?php } ?> /> </div> <div class="label_top"> <label for="group1">Second Option </label> </div> <div class="label_desc"> <label for="group1">This is Second Option </label> </div> </div> 

The only problem that I encountered, if I change the identifier of the radio, it works fine, but I need the same identifier, because I need its value at the end to save to the database.

+6
jquery radio-button
source share
2 answers

You are misleading the name attribute with the id attribute.

They must have the same name but a different identifier.

For example:

 <input type="radio" name="group1" id="group1_0" value="0"> <input type="radio" name="group1" id="group1_1" value="1"> <label for="group1_0">CLicky 0</label> <label for="group1_1">CLicky 1</label> 
+15
source share

The identifier and login do not have to match. Leave the name and change the identifier of the second radio to another (and change the second attribute β€œfor” to this identifier). When you submit the form to the server, you will receive the value using the "name" attribute. The server does not know anything about the ID.

+1
source share

All Articles