Click image and select radio not working - html

I have this code and cannot get it to select the radio when I click on it's image.
I'm I missing something?
Here is the current code:
<label style="display: inline; " for="test1">
<img src="images/image1.jpg" />
<input checked="checked" class="select_control" id="select1" name="test1" type="radio" value="value1" />
</label>
<label style="display: inline; " for="test2">
<img src="images/image2.jpg" />
<input checked="checked" class="select_control" id="select2" name="test2" type="radio" value="value2" />
</label>

The for attribute in label should match input's id and not name. name is used for grouping radio buttons and checkboxes (when it's the same name their are in a group, so checking one will will uncheck the other).
<label for="test1">
<img src="image1.jpg" />
<input id="test1" name="test" type="radio" value="value1" />
</label>
<label for="test2">
<img src="image2.jpg" />
<input id="test2" name="test" type="radio" value="value2" />
</label>
Here's a working example of your code: http://jsfiddle.net/nXb5a/

the for attribute of the label should reference the id of the input it is for not the name
see:
http://jsfiddle.net/EtvLu/

the for attribute should be the id of the element it is referring to, and both radio buttons should have the same name (assuming you want them as one group):
<label style="display: inline; " for="select1">
<img src="images/image1.jpg" />
<input checked="checked" class="select_control" id="select1" name="test1" type="radio" value="value1" />
</label>
<label style="display: inline; " for="select2">
<img src="images/image2.jpg" />
<input checked="checked" class="select_control" id="select2" name="test1" type="radio" value="value2" />
</label>

Related

HTML RADIO BUTTON SELECTING BOTH OPTIONS INSTEAD OF ONE

Kindly Select the service you require
<input type="radio" id="currConverter" name="currConverter" value="currConverter" />
<label for="currConverter">Currency Converter</label> <br />
<input type="radio" id="pbChecker" name="pbChecker" value="pbChecker" />
<label for="pbChecker">Prize Bond Checker</label> <br />
<input type="submit" class="submit" />
</form>
I have a form element inside which i have put two radio buttons but want the user to select only one option.When i am clicking on these one by one , both options are getting selected instead of the one on which i clicked.Any solution to this ?
Link to w3School
You have to keep same name. in your case:
<input type="radio" id="currConverter" name="pbChecker"value="currConverter"/>
<label for="currConverter">Currency Converter</label> <br />
<input type="radio" id="pbChecker" name="pbChecker" value="pbChecker" />
<label for="pbChecker">Prize Bond Checker</label> <br />
<input type="submit" class="submit" />
</form>

radio button align with text

I am trying to get my gender button to align with my radio image buttons this is the codes have so far. It gives me the text above the button. Thank you in advance
<div class="genderalign">
<p>Choose:</p>
<input type="radio" name="option" value="1" id="choose-1" />
<label for="choose-1">
<img src="/images/femaleC.png" />
</label>
<input type="radio" name="option" value="2" id="choose-2" />
<label for="choose-2">
<img src="/images/maleC.png" />
</label>
</div>
I've corrected the misplaced </div> so your HTML is now like this.
Then just apply flexbox
.genderalign {
display: flex;
align-items: center;
}
<div>
<div class="genderalign">
<p>Choose:</p>
<input type="radio" name="option" value="1" id="choose-1" />
<label for="choose-1">
<img src="/images/femaleC.png"/>
</label>
<input type="radio" name="option" value="2" id="choose-2" />
<label for="choose-2">
<img src="/images/maleC.png" />
</label>
</div>
</div>

Radio type button not working properly

My code:
Radio text input type not working properly
All radio buttons are selected.
<input type="radio" name="cash" id="cash" value="CASH"/>CASH<br />
<input type="radio" name="card" id="card" value="CARD"/>CARD<br />
<input type="radio" name="netbank" id="netbank" value="NETBANKING"/>NETBANKING<br />
<input type="radio" name="paypal" id="paypal" value="PAYPAL"/>PAYPAL<br />
Demo: https://jsfiddle.net/hw7u83vm/
Radios with the same name are treated as a group. When you select one button, all other buttons in the same group are unselected.
Use
<input type="radio" name="type" id="cash" value="CASH"/>CASH<br />
<input type="radio" name="type" id="card" value="CARD"/>CARD<br />
<input type="radio" name="type" id="netbank" value="NETBANKING"/>NETBANKING<br />
<input type="radio" name="type" id="paypal" value="PAYPAL"/>PAYPAL<br />
<input type="radio" name="Payment" id="cash" value="CASH"/>CASH<br />
<input type="radio" name="Payment" id="card" value="CARD"/>CARD<br />
<input type="radio" name="Payment" id="netbank" value="NETBANKING"/>NETBANKING<br />
<input type="radio" name="Payment" id="paypal" value="PAYPAL"/>PAYPAL<br />
Use this, i have changed the Name to "Payment".
Name should be same
For radio button working properly, You must have name property common for all radio buttons
<input type="radio" name="payment" id="cash" value="CASH"/>CASH<br />
<input type="radio" name="payment" id="card" value="CARD"/>CARD<br />
<input type="radio" name="payment" id="netbank" value="NETBANKING"/>NETBANKING<br />
<input type="radio" name="payment" id="paypal" value="PAYPAL"/>PAYPAL<br />
DEMO : https://jsfiddle.net/md2o2m6x/
If you want to allow the user to be able to select more than 1 box, use the input type checkbox, but the name attribute must be the same.
<input type="radio" name="cash" id="cash" value="CASH"/>CASH<br />
<input type="radio" name="cash" id="card" value="CARD"/>CARD<br />
<input type="radio" name="cash" id="netbank" value="NETBANKING"/>NETBANKING<br />
<input type="radio" name="cash" id="paypal" value="PAYPAL"/>PAYPAL<br />
If you want the user to select only one box, use the input type radio, but the name attribute must be the same to make it work properly
CASH
CARD
NETBANKING
PAYPAL

Why am i able to check multiple radio buttons at once?

This is the code i use for my form and I'm using radio button as i know only one can be ticked but for some reason I can click on multiple. How do I fix this?
<form name="Question1" method="post" onsubmit="return CheckAnswer1()">
<input type="radio"
name="Q1opt1"
value="1" >Having loads of pictures on the website<br /><br />
<input type="radio"
name="Q1opt2"
value="2" >Making the website nice and pretty.<br /><br />
<input type="radio"
name="Q1opt3"
value="3" >Making the website most user friendly.<br /><br />
<input type="submit" value="Select Your Answer and Click Here" />
</form>
They should have the same name but different values, that's how the browser distinguishes between sets of radio button groups:
<form name="Question1" method="post" onsubmit="return CheckAnswer1()">
<input type="radio"
name="Q1opt"
value="1" >Having loads of pictures on the website<br /><br />
<input type="radio"
name="Q1opt"
value="2" >Making the website nice and pretty.<br /><br />
<input type="radio"
name="Q1opt"
value="3" >Making the website most user friendly.<br /><br />
<input type="submit" value="Select Your Answer and Click Here" />
</form>
It's because their names are all the same.
Try this:
<input type='radio' name='Qstn1' Id='q1Opt1' value='1' />Opt 1<br />
<input type='radio' name='Qstn1' Id='q1Opt2' value='2' />Opt 2<br />
<input type='radio' name='Qstn1' Id='q1Opt3' value='3' />Opt 3<br />

How to identify which radio button is accepted?

How can I identify which radio button is accepted?
How do I prevent a user being able to select multiple options when I use radio buttons?
<input type='radio' name='one'>option1<br />
<input type='radio' name='two'>option2<br />
<input type='radio' name='three'>option3<br />
<input type='radio' name='four'>option4<br />
<input type='radio' name='five'>option5<br />
Thats the code I use, thanks for reading.
You need to use the "name" attribute to tie them all together, use the value attribute to give them different values.
<input type="radio" name="number" value="one" /> One<br />
<input type="radio" name="number" value="two" /> Two<br />
<input type="radio" name="number" value="three" /> Three<br />
Think of name as last name... For example, if you had Bart, Lisa, Homer, Marge and Maggie, the name would be their last name: Simpson, the value would be the said names:
<input type="radio" name="Simpson" value="Bart" /> Bart<br />
<input type="radio" name="Simpson" value="Lisa" /> Lisa<br />
<input type="radio" name="Simpson" value="Marge" /> Marge<br />
<input type="radio" name="Simpson" value="Homer" /> Homer<br />
<input type="radio" name="Simpson" value="Maggie" /> Maggie<br />
you should give them the same name
Also the order of name/value pair matter's I guess.Name should appear before the order
I know! Do like this:
<label><input type="radio" name="a">1</label>
<label><input type="radio" name="a">2</label>
<label><input type="radio" name="a">3</label>
Give everything same value for 'name' attribute. You add the name for the radio buttons