jQuery Progress Bar with Radio Buttons - javascript

I am creating a progress bar that pops-up and shows you continuous progress as you fill out inputs, and it works well with all input type except radio buttons. This is because each input needs a "required" tag for it to register as progress, however this means I would have to put a required tag for each radio option, so instead of showing you answered the question by selecting one of the radio answers, you have to click on all of the radio buttons. I tried applying the "required" tag to a container holding both radio buttons but it doesn't work.
Here is my codepen so you can see exactly what I am working with.
http://codepen.io/er40/pen/ugdqa
Thanks for any help!

There is a more complicated work around with a required hidden input that changes value based on radios selected, but i think for what you are doing, conceptually, it makes more sense to have a single checkbox there with a value of "yes" because you want to make sure the user selects "yes" before continuing.
right now there are two radio buttons that i can select at the same time and still progress, which doesn't make a lot of sense.
edit: the complicated workaround
add a hidden, required input to the radio group:
<input type="radio" name="radio" value="yes">YES
<input type="radio" name="radio" value="no">NO
<input type="hidden" class="radio_selected" required="required" />
and in your javascript, something along the lines of this to give the hidden input a value:
$('input[type="radio"]').click(function() {
var radio_selected = $(this).next('.radio_selected');
if (radio_selected.val() !== 'true') {
radio_selected.val("true");
}
});
then modify your plugin to detect that change.
this only really works because your radios can't be deselected.

Related

how to make action after clicking a radio button on a site made by html, css

I have made a a site using html and css where users use radio buttons to make choice now I am looking forward to putting action to the choices made. If a user chooses an option and action should be made, however I do not know how to put action to a radio button action. I require help please!
You could use the addEventListener method. So, say you have a the following HTML:
<input type="radio" name="myRadio" value="1">
Then you can use this code:
var radio = document.getElementsByName("myRadio")
radio.forEach(r => r.addEventListener('change', myFunc))
You can also bind the function in your HTML, using the onchange attribute:
<input type="radio" name="myRadio" value="1" onchange="myFunc()">
You can see more details in previous questions that seem very similar to yours:
onchange not working with radio button
OnChange event handler for radio button (INPUT type="radio") doesn't work as one value
Radio Input onChange only fires once?
Also, as suggested by #devdgehog, you could give a look at the documentation on:
addEventListener: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
inputs's onchange: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event

Link duplicate radio button forms

So, I want to display a set of radio buttons several places on a page. I want the state of the radio buttons to be linked, select option A on one form should select option A in all forms.
Sorry for not including examples.
Here is the idea:
<form id="serverForm">
<input type="radio" name="#(site.SiteID)" class="serverRadio" value="All"> All
<input type="radio" name="#(site.SiteID)" class="serverRadio" value="DS1"> DS1
<input type="radio" name="#(site.SiteID)" class="serverRadio" value="DS2"> DS2
<input type="radio" name="#(site.SiteID)" class="serverRadio" value="IS1"> IS1
</form>
This form is going to be created multiple times dynamically depending on the size of the loops its contained in. I want each of these forms to essentially act as duplicated. Clicking an option on one will update all.
Give a class attribute to all Radiobuttons.
Add an "on Click" event on that class.
Check the clicked radio button's value in the event
Compare the value with other radio buttons (in a loop for all radio buttons), if it's the same put the attribute "checked" on true
P.S.: Share your code next time so an easy code example can be provided or even the full solution.
1.)Make all the position 1 buttons of forms to same div and position 2 buttons to other same div and so on.
2.)Use any technique(like directing to any function or adding an onClick event in jquery) to check the changed class like:-
$(".class_to_be_checked").attr("checked","checked");

in firefox entering data into a textbox which acts as a radio button needs a double click

In mozilla firefox entering data into a textbox which acts as a radio button needs a double click...how to make it possible through single click.Even after selecting the radio button and If i click the textbox once and try to enter only the radio button gets selected and the data is not entered.
For Firefox, the first click in to select the radio button, which gets the focus (honnestly don't know why it's different with other browsers).
I think your solution will be to use Javascript... See this jdfiddle, I've update your code ;)
The idea is to have two inputs not linked in the HTML, but linked via the onclick (or onfocus) function, like:
<input type="radio" name="address-chosen" value="1" id="address-switch_1" />
<input type="text" name="address-item_1" value="1" onclick="selectRadioButton('address-switch_1')"/>
My question is: what's your final objective? Because when you submit the form, you'll have to take into account that you have two separate inputs... or maybe update the value of the radio button with JS, too?

Angular Form Validation Using Ng-Required

FIDDLE HERE: http://jsfiddle.net/TegFf/48/
I have a form with radio buttons (please Fiddle below) that should validate if:
you choose a radio button that has a dollar amount associated
you choose custom AND enter a value
My problem, I think, is that the Ng-Required I have put on an input field is not properly registering whether it is or is not required.
<input name="donation" type="radio" value="yes" ng-model="manual" required="false">
<input type="number" ng-model="donation" ng-required="manual === 'yes'">
http://jsfiddle.net/TegFf/49/
Couple of things:
First radio input has a different name.
Wrapping the manual amount inside a label together with the radio button prevents you from focusing the field.
An AngularJS form is not valid until all fields are valid, so it's easier if you add more debug code to see which field is actually invalid.
Your first radio button needs to have 'name="donation"' added to it. Another issue is that once variable manual is set to 'yes', it will always stay yes. You should either reduce the number of your variables, or set up a custom validation in a directive.

Need to check all radio boxes on a page using javascript

I need to use javascript to check all radio boxes with a certain ID on a page. The radio buttons all have different names, and are grouped by 3, one for approve, one for deny, one for review...
<input type=radio name='21' value='approved' id='approved' title='Approve'>
<input type=radio name='21' value='denied' id='denied' title='Deny'>
<input type=radio name='21' value='review' id='review' checked title='Do nothing right now'>
...and so on. I've searched on this site and all over the googles, not really finding a solution that works for me. I have another set of radio buttons on top of the page, that I want to use to control the others, so if I click the "approve" radio up top, all the approve radios are selected, deny does all the denied radio boxes on the page etc.
I am using an onclick on the top radio buttonset to fire a javascript function, but I've no idea what to tell the function to do. I assume that jquery would be able to do this nicely, but cannot seem to come up with the code to do so.
Try a click function on all radio and update the selection based on its value. See below,
// v--- Refined the selector as you want this to happen only when clicking on the
// controller radio options.
$('.controller:radio').click(function () {
$(':radio[value=' + this.value + ']')).prop('checked', true);
});
DEMO: http://jsfiddle.net/KvdNq/
What I would do is actually create the groups within separate DIVS. Then you can loop through all the radios within that particular div and dont need to care about what the IDS are for the respective Radio Buttons.
<div id="group1">
<input type="checkbox" value="group1"/> Check all in this group
<input type = "radio" value="xx" />
<input type="radio" value="yy" />
</div>
Now you can simply create a function that takes the value of the checkbox, then loops through the matching div, checking all the RADIO BUTTONS within it. Make sense?

Categories