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,510 points
5,383 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,880 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, 2022 in JQuery by rajatha
• 7,640 points
12,727 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, 2022 in JQuery by Edureka
• 13,670 points
697 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, 2022 in JQuery by gaurav
• 23,260 points
717 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, 2022 in JQuery by rajatha
• 7,640 points
22,120 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,880 points
4,120 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,880 points
9,894 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,880 points
1,420 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,880 points
6,144 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,880 points
2,690 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,880 points
41,817 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP