How to set radio option checked onload with jQuery

0 votes
How to set radio option checked onload with jQuery?

Need to check if no default is set and then set a default
Nov 24, 2020 in JQuery by kartik
• 37,500 points
1,769 views

1 answer to this question.

0 votes

Hii,

Say you had radio buttons like these, for example:

<input type='radio' name='gender' value='Male'>
<input type='radio' name='gender' value='Female'>

And you wanted to check the one with a value of "Male" onload if no radio is checked:

$(function() {
    var $radios = $('input:radio[name=gender]');
    if($radios.is(':checked') === false) {
        $radios.filter('[value=Male]').prop('checked', true);
    }
});

Hope it works!

answered Nov 24, 2020 by Niroj
• 82,720 points

Related Questions In JQuery

0 votes
1 answer

How to set the 'selected option' of a select dropdown list with jquery

Using the jQuery change() method; you can ...READ MORE

answered Jun 17 in JQuery by rajatha
• 5,040 points
19 views
0 votes
1 answer

How to check a radio button with jQuery?

For versions of jQuery equal or above ...READ MORE

answered Jun 3 in JQuery by Edureka
• 13,640 points
17 views
0 votes
1 answer

How to check a radio button with jQuery?

“jquery datepicker format” Code Answer's $('#timePicker'). datetimepicker({ // dateFormat: ...READ MORE

answered Jun 10 in JQuery by gaurav
• 13,560 points
11 views
0 votes
1 answer

How to check a radio button with jQuery?

We can check the status of a ...READ MORE

answered Jun 10 in JQuery by rajatha
• 5,040 points
10 views
0 votes
1 answer

How to set jquery input select all on focus?

Hello @kartik, Try using click instead of focus. It seems to ...READ MORE

answered Nov 24, 2020 in JQuery by Niroj
• 82,720 points
1,374 views
0 votes
1 answer

How to make $.post() use contentType=application/json in jquery?

Hii, Try this: $.ajax({ url:url, type:"POST", ...READ MORE

answered Nov 24, 2020 in JQuery by Niroj
• 82,720 points
2,700 views
0 votes
1 answer

How to add a “readonly” attribute to an <input>?

Hello, For jQuery <1.9 $('#inputId').attr('readonly', true); ...READ MORE

answered Nov 24, 2020 in JQuery by Niroj
• 82,720 points
306 views
0 votes
1 answer

How to find the version of an installed node.js/npm package?

Hello, npm view <package> version - returns the latest ...READ MORE

answered Nov 24, 2020 in Node-js by Niroj
• 82,720 points
2,326 views
0 votes
1 answer

How to convert form data to JavaScript object with jQuery?

Hello @kartik, You can use: function form_to_json (selector) { ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,720 points
1,467 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,720 points
24,112 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP