Hi All,
we need to trigger the radio button event in page _load using javascript automatically without any manual interaction. Can anyone suggest with example?
Thanks
Karthik. k
Hi All,
we need to trigger the radio button event in page _load using javascript automatically without any manual interaction. Can anyone suggest with example?
Thanks
Karthik. k
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satya KarkiRank #78 · 24.6K reputationPosted Sep 26, 2022, 5:04 AM EDT
Try this
Sachin SinghRank #66 · 26.2K reputationPosted Sep 26, 2022, 4:54 AM EDT
You can trigger the click event because change event won't work for initial load
$(function(){ $("input:radio[name='rdoAnything'}:first").prop("checked", true).trigger("click"); })Rijwan AnsariRank #82 · 24.2K reputationPosted Sep 26, 2022, 5:02 AM EDT
Hi,
I am not sure about the question. Generally, the radio button event is either click or change, which you can do in JavaScript. However, you can trigger event page load as shown:
Change Event
$('input[type=radio][name=bedStatus]').change(function() { if (this.value == 'allot') { alert("Allot Thai Gayo Bhai"); } else if (this.value == 'transfer') { alert("Transfer Thai Gayo"); } });Click Event
$('#radio-button-id').click(function() { if($('#radio-button-id').is(':checked')) { //input where you put a value $('#program').val("radio-button-text"); } });Uday DodiyaRank #239 · 10.3K reputationPosted Sep 26, 2022, 7:29 AM EDT
Hi Karthik,
Try Following
Html Code
Java Script
if($('input[name="button1"]').is(':checked')){ alert('1 is checked'); } if($('input[name="button2"]').is(':checked')){ alert('2 is checked'); }Reference : http://jsfiddle.net/tVRrb/