I have a pair of div elements
<div class="tab-pane active" id="home">
<div class="tab-pane" id="profile">
Both of these divs contain forms with a hidden field
<input type="hidden" name="selectedRadioValue" id="selectedRadioValue">
Therefore, I want to develop a javascript function that can set a value for the hidden input field.
if($("#home").hasClass("active")) {
assign "radio1" as the value in the hidden input field
}
else if($("#profile").hasClass("active")) {
assign "radio2" as the value in the hidden input field
}
I apologize for asking this kind of question. I am new to javascript and have attempted some code on my own but need assistance. How can I achieve this? Please provide guidance.
Solution:
$(function () {
$('button').on('click', function () {
if ($("#home").hasClass("active")) {
$('.selectedRadioValue').val('radio1');
} else if ($("#profile").hasClass("active")) {
$('.selectedRadioValue').val('radio2');
}
});
});