Multiple star rating css [duplicate] - html

Is it possible to have multiple radio button groups in a single form? Usually selecting one button deselects the previous, I just need to have one of a group deselected.
<form>
<fieldset id="group1">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
<fieldset id="group2">
<input type="radio" value="">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
</form>

Set equal name attributes to create a group;
<form>
<fieldset id="group1">
<input type="radio" name="group1">value1</input>
<input type="radio" name="group1">value2</input>
</fieldset>
<fieldset id="group2">
<input type="radio" name="group2">value1</input>
<input type="radio" name="group2">value2</input>
<input type="radio" name="group2">value3</input>
</fieldset>
</form>

This is very simple you need to keep different names of every radio input group.
<input type="radio" name="price">Thousand<br>
<input type="radio" name="price">Lakh<br>
<input type="radio" name="price">Crore
</br><hr>
<input type="radio" name="gender">Male<br>
<input type="radio" name="gender">Female<br>
<input type="radio" name="gender">Other

Just do one thing,
We need to set the name property for the same types. for eg.
Try below:
<form>
<div id="group1">
<input type="radio" value="val1" name="group1">
<input type="radio" value="val2" name="group1">
</div>
</form>
And also we can do it in angular1,angular 2 or in jquery also.
<div *ngFor="let option of question.options; index as j">
<input type="radio" name="option{{j}}" value="option{{j}}" (click)="checkAnswer(j+1)">{{option}}
</div>

in input field make name same
like
<input type="radio" name="option" value="option1">
<input type="radio" name="option" value="option2" >
<input type="radio" name="option" value="option3" >
<input type="radio" name="option" value="option3" >

To create a group of inputs you can create a custom html element
window.customElements.define('radio-group', RadioGroup);
https://gist.github.com/robdodson/85deb2f821f9beb2ed1ce049f6a6ed47
to keep selected option in each group, you need to add name attribute to inputs in group, if you not add it then all is one group.

Related

Last option is getting selected as default in HTML

In my form, the last option is getting selected as default. How can avoid this?
<form action=" url " method=" post">
<h3>Question</h3>
<input type="radio" name="choice" value="option1" checked> option1<br>
<input type="radio" name="choice" value="option2" checked>option2<br>
<input type="radio" name="choice" value="option3" checked>option3<br>
<input type="radio" name="choice" value="option4" checked>option4<br>
<input type="radio" name="choice" value="option5" checked> option5<br>
<input type="submit" value="Submit Answer">
</form>
I want select none of the radio buttons at the start.
Remove checked attribute from all the inpputs
<input type="radio" name="choice" value="option1"> option1<br>
In my form, the last option is getting selected as default.
You've checked every one of your radio buttons, but only one in a group can be checked.
Error recovery is checking the last one.
How can avoid this?
Check only the one you want to be checked.
$('#submit').click(function(){
if(typeof $('input[name=choice]:checked', '#myForm').val()=="undefined"){
alert("please select oiption");
}else{
alert($('input[name=choice]:checked', '#myForm').val());
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm" action=" url " method=" post">
<h3>Question</h3>
<input type="radio" name="choice" value="option1" > option1<br>
<input type="radio" name="choice" value="option2" >option2<br>
<input type="radio" name="choice" value="option3" >option3<br>
<input type="radio" name="choice" value="option4" >option4<br>
<input type="radio" name="choice" value="option5" > option5<br>
<input type="submit" id="submit" value="Submit Answer">
</form>

Multiple radio button groups in one form

Is it possible to have multiple radio button groups in a single form? Usually selecting one button deselects the previous, I just need to have one of a group deselected.
<form>
<fieldset id="group1">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
<fieldset id="group2">
<input type="radio" value="">
<input type="radio" value="">
<input type="radio" value="">
</fieldset>
</form>
Set equal name attributes to create a group;
<form>
<fieldset id="group1">
<input type="radio" name="group1">value1</input>
<input type="radio" name="group1">value2</input>
</fieldset>
<fieldset id="group2">
<input type="radio" name="group2">value1</input>
<input type="radio" name="group2">value2</input>
<input type="radio" name="group2">value3</input>
</fieldset>
</form>
This is very simple you need to keep different names of every radio input group.
<input type="radio" name="price">Thousand<br>
<input type="radio" name="price">Lakh<br>
<input type="radio" name="price">Crore
</br><hr>
<input type="radio" name="gender">Male<br>
<input type="radio" name="gender">Female<br>
<input type="radio" name="gender">Other
Just do one thing,
We need to set the name property for the same types. for eg.
Try below:
<form>
<div id="group1">
<input type="radio" value="val1" name="group1">
<input type="radio" value="val2" name="group1">
</div>
</form>
And also we can do it in angular1,angular 2 or in jquery also.
<div *ngFor="let option of question.options; index as j">
<input type="radio" name="option{{j}}" value="option{{j}}" (click)="checkAnswer(j+1)">{{option}}
</div>
in input field make name same
like
<input type="radio" name="option" value="option1">
<input type="radio" name="option" value="option2" >
<input type="radio" name="option" value="option3" >
<input type="radio" name="option" value="option3" >
To create a group of inputs you can create a custom html element
window.customElements.define('radio-group', RadioGroup);
https://gist.github.com/robdodson/85deb2f821f9beb2ed1ce049f6a6ed47
to keep selected option in each group, you need to add name attribute to inputs in group, if you not add it then all is one group.

restrict multiple selection of radio button in HTML?

The below HTML code i have allows multiple selection of radio button ? How do i limit it so that only one can be chooses at a time from the list
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="Arrived/Left" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="Delayed" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="Canceled" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="getupdate" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="Other" id="Other" value="Other">
</fieldset>
First this is not jQuery.. this is HTML..
Second you can do that by giving all the radio buttons of the same group (where you want only one to be selected) the same name..
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="status" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="status" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="status" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="status" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="status" id="Other" value="Other">
</fieldset>
use name attribute to group your radio button
<fieldset data-role="controlgroup">
<legend></legend>
<label for="Arrived/Left">Arrived/Left Destination</label>
<input type="radio" name="status" id="Arrived/Left" value="Arrived/Left">
<label for="Delayed">Delayed</label>
<input type="radio" name="status" id="Delayed" value="Delayed">
<label for="Canceled">Canceled</label>
<input type="radio" name="status" id="Canceled" value="Canceled">
<label for="getupdate">Post to Get Update ?</label>
<input type="radio" name="status" id="getupdate" value="getupdate">
<label for="Other">Other</label>
<input type="radio" name="status" id="Other" value="Other">
</fieldset>
You define radio button groups with the name property (radio buttons with the same name belong to the same group).
You are having a different name for each of your radio. Change the names of all the input radio to a single name. The radios having the same name will behave as a single group which is what your requirement.
*You haven't closed the input tags.
Hope this helps.

Multiple the same form label in a page issue

I have a multiple forms in one page. Each form has exactly the same content. But i encountered an issue regarding with my labels. I know that label "for" tag should be unique and pointed to the element id but I have to multiply the form for some reason.
Please refer to my code found in jsfiddle my code
<form>
<label for="option1">Option 1</label>
<input type="radio" id="option1" name="options">
<label for="option2">Option 2</label>
<input type="radio" id="option2" name="options">
<label for="option3">Option 3</label>
<input type="radio" id="option3" name="options">
</form>
<!-- another form but the same content -->
<form>
<label for="option1">Option 1</label>
<input type="radio" id="option1" name="options">
<label for="option2">Option 2</label>
<input type="radio" id="option2" name="options">
<label for="option3">Option 3</label>
<input type="radio" id="option3" name="options">
</form>​
Thanks
Either:
Generate a prefix that you apply to all the ids in a given instance of a form
Don't use for or id and place the form controls inside the label elements.

Radiobutton array (HTML)

If i have two inputs of type text with the same name, like this:
<input type="text" name="task" id="task1" value="begin">
<input type="text" name="task" id="task2" value="end">
When i submit the form task is automatically sent as an array (task[0]='begin', task[1]='end').
This is very useful for many reasons, for instance i don't have to worry about serializing the result, I can use a sortable to re-sort and when I submit it's already in the right order.
But if i want to use radio buttons, i have to use several inputs with the same name already.
Is there a way I could keep this functionality with radio buttons?
For instance:
<input type="text" name="task" id="task1" value="begin">
<input type="radio" name="time" id="time11" value="early" checked="checked">
<input type="radio" name="time" id="time12" value="noon">
<input type="radio" name="time" id="time13" value="late">
<input type="text" name="task" id="task2" value="end">
<input type="radio" name="time" id="time21" value="early">
<input type="radio" name="time" id="time22" value="noon" checked="checked">
<input type="radio" name="time" id="time23" value="late">
I want that when submitted i get time[0]='early' and time[1]='noon'
Try this:
<input type="text" name="task[0]" id="task1" value="begin">
<input type="radio" name="time[0]" id="time11" value="early" checked="checked">
<input type="radio" name="time[0]" id="time12" value="noon">
<input type="radio" name="time[0]" id="time13" value="late">
<input type="text" name="task[1]" id="task2" value="end">
<input type="radio" name="time[1]" id="time21" value="early">
<input type="radio" name="time[1]" id="time22" value="noon" checked="checked">
<input type="radio" name="time[1]" id="time23" value="late">
Then you'd get: task[0]=begin, time[0]=early, task[1]=end and time[1]=noon.