Html 5 required on radio button wil not reset - html

Why won't an html5 required on radio button group reset with form reset button if it was selected. for example you have a radio button group in a form with the html5 required set if you select one of the radio buttons then click the reset form button it doesn't reset the radio button group required validation so even though the form was reset. So basically you click submit button without selecting anything the radio buttons are given an outline in red then you select one and click reset you are then able to submit the form without selecting a radio button? any help on why it does this would be greatly appreciated. I may misunderstand how its supposed to work.
Simple test
<html>
<form>
<input type="radio" name="test" required>
<input type="radio" name="test" required>
<input type="submit" value="submit">
<input type="reset" value="cancel">
</form>
</html>

It is because you are using same name for the radio buttons.If you give the same name only one radio button of the can be checked.And so it passes the Validation
Example : Different name for radio buttons.
<form>
<input type="radio" name="test" required>
<input type="radio" name="test2" required>
<input type="submit" value="submit">
<input type="reset" value="cancel">
</form>
Example : Same name for radio buttons.
<form>
<input type="radio" name="test" required>
<input type="radio" name="test" required>
<input type="submit" value="submit">
<input type="reset" value="cancel">
</form>

You need to give them different value attributes (but the same name so it's clear that those are two different options for the same "question" and only one of them should be selectable):
<html>
<form>
<input type="radio" name="test" value="1" required>1
<input type="radio" name="test" value="2" required>2<br>
<input type="submit" value="submit">
<input type="reset" value="cancel">
</form>
</html>

Related

How to auto submit when all radio selected?

I want to auto submit when all radio selected, here is my code.
<form name="quiz" ng-submit="quiz.answer(selected)">
<label>
<input type="radio" ng-model="selected" ng-value="red">
Red
</label><br/>
<label>
<input type="radio" ng-model="selected" ng-value="green">
Green
</label><br/>
<input type="submit" id="submit" value="Submit" />
</form>
You should add a java-script function and trigger it every time the user clicks on one of the radio buttons.
Here, as there are only two radio buttons, I have used && but in a case that the number of them is more than two you can have a counter value for all of them as well.
Here's the code that you can use:
function check() {
if (document.getElementById("first").checked && document.getElementById("second").checked) {
alert("triggered");
document.getElementById('myForm').submit();
}
}
<!DOCTYPE html>
<html>
<body>
<form name="quiz" id="myForm" action="https://www.google.com">
<label>
<input type="radio" ng-model="selected" ng-value="red" id="first" onClick="check();">
Red
</label><br/>
<label>
<input type="radio" ng-model="selected" ng-value="green" id="second" onClick="check();">
Green
</label><br/>
<input type="submit" id="submit" value="Submit" />
</form>
</body>
</html>
Add an onClick() event ...
Give your form an ID
<form id="quiz" name="quiz" ng-submit="quiz.answer(selected)">
Then call that ID and submit
<input type="radio" ng-model="selected" ng-value="green"
onClick="document.getElementById('quiz').submit();">
You can give check whether the radio is selected or not using JS. Later you can click the submit button using JS if the condition meets your use case.
To click button:
document.getElementById('submit').click();

Radio Button won't check in Plain HTML

The web page I am working on requires a few html radio buttons at the bottom of a large picture. I included the id the type the name. But when I load the page, none of the radios will select.
<fieldset>
<form id="radio" action="" method="GET">
<input id="pic-1" type="radio" name="jumbotron-radio" value="1">
<input id="pic-2" type="radio" name="jumbotron-radio" value="2">
<input id="pic-3" type="radio" name="jumbotron-radio" value="3">
</form>
</fieldset>

Why the submit button doesn't show the text?

Why the submit button doesn't show the text?
It shows:
The tag for it: <input type=submit name="OK" value=""/>
Thought <input type=submit name=OK value=""/> would help,but not.
The value attribute will be shown in the button.
<input type=submit name=OK value="button"/>
Try this:
<input type="submit" name="OK" value="Submit Label"/>
See:
https://www.w3schools.com/tags/att_input_type.asp
You have to define into value="" the text to display.
Example :
<input type=submit name="OK" value="OK" />

How do I change the position of a radio button in html?

I am programming a webpage that uses a series of radio buttons and drop down menus to change the data that is displayed on the screen. Each radio corresponds to one of the drop down menus and I want to line them up but I can't figure out how to get the third one to appear to the right of the other two instead of below them. Can anyone help?
Here's my code:
<form action="" style="float: left">
<input type="radio" name="yearLessGreaterOption" value="<" onchange="setYearLessGreaterFilter(this.value)"><
<input type="radio" name="yearLessGreaterOption" value="=" onchange="setYearLessGreaterFilter(this.value)" checked>=
<input type="radio" name="yearLessGreaterOption" value=">" onchange="setYearLessGreaterFilter(this.value)">>
</form>
<form action="">
<input type="radio" name="roundLessGreaterOption" value="<" onchange="setRoundLessGreaterFilter(this.value)"><
<input type="radio" name="roundLessGreaterOption" value="=" onchange="setRoundLessGreaterFilter(this.value)" checked>=
<input type="radio" name="roundLessGreaterOption" value=">" onchange="setRoundLessGreaterFilter(this.value)">>
</form>
<form action="">
<input type="radio" name="goalsH1LessGreaterOption" value="<" onchange="setGoalsH1LessGreaterFilter(this.value)"><
<input type="radio" name="goalsH1LessGreaterOption" value="=" onchange="setGoalsH1LessGreaterFilter(this.value)" checked>=
<input type="radio" name="goalsH1LessGreaterOption" value=">" onchange="setGoalsH1LessGreaterFilter(this.value)">>
</form>
Here's a picture of the page in question:
Is there a reason you want them in form tags? If you remove the tags, they will appear aligned. Otherwise, adding style="float:left;" to the other form tags will do the trick.
In your case, adding the style="float: left" on the other forms should do what you want.

Creating a simple radio buttons form with greyed-out buttons

In the following code:
<form>
<input type="radio" style="disabled:true">Alpha<br>
<input type="radio" style="enabled:false">Beta<br>
<input type="radio">Gamma<br>
</form>
1) Why is it allowing me to select more than one radio button at a time?
2) How to I "grey out" specific radio buttons? The "enabled" and "disabled" attributes do not seem to be working.
To make a group of radio buttons, give them all the same name:
<form>
<input type="radio" name="group1">Alpha<br>
<input type="radio" name="group1">Beta<br>
<input type="radio" name="group1">Gamma<br>
</form>
Demo
To disable a radio button, use the disabled attribute in its tag:
<form>
<input type="radio" name="group1">Alpha<br>
<input type="radio" name="group1">Beta<br>
<input type="radio" name="group1" disabled>Gamma<br>
</form>
Demo
Disabled is not a CSS attribute so it is not defined within the style attribute.
As commented above you can also wrap the <input> in a <label> tag like so:
<form>
<label><input type="radio" name="group1">Alpha</label><br>
<label><input type="radio" name="group1">Beta</label><br>
<label><input type="radio" name="group1" disabled></label>Gamma<br>
</form>
Or you can link the label with the inputs id:
<label for="alpha">Alpha</label>
<input type="radio" name="group1" id="alpha">
Then the user can click on the text instead of just the radio button.
Demo
The disabled attribute isn't a css style. You disable an input like this:
<form>
<input type="radio" name="radGroup">Alpha<br>
<input type="radio" name="radGroup" disabled>Beta<br>
<input type="radio" name="radGroup">Gamma<br>
</form>
notice also the name attribute. This will prevent multple radio buttons been selected at once. Each input in the group must share the same name
DEMO
a group of radiobuttons must have the same same to select only one:
use the html disabled attribute to disable a radio <input type="radio" disabled>
so your solution would be:
<form>
<input type="radio" name="rb1">Alpha<br>
<input type="radio" name="rb1">Beta<br>
<input type="radio" name="rb1" disabled>Gamma<br>
</form>