Reputation: 371
I'm new to JavaScript so need a help please. Basically I've two radio buttons and one submit button. I want to use JS function when submit button is clicked to pick the value of radio button.
<td align="right" style="width: auto">
@Html.RadioButton("SelectedOption", LinkOption.Link, true) Link Account
</td>
<td align="left" style="width: auto">
@Html.RadioButton("SelectedOption", LinkOption.DeLink, false) De-Link Account
</td>
<td align="right" style="width:50%">
<input type="submit" id="linkAccountSubmit" onclick="activeDeLink()" />
</td>
And the JavaScript function is; where I want to use the if statement to pick the value of radio buttons
function activeDeLink() {
if (............) {
$('.hiddenLink').each(function () {
$(this).removeClass('hiddenLink');
});
}
else
{.......}
}
Upvotes: 0
Views: 706
Reputation:
you can get the value in this way:
$('input[name="SelectedOption"]').val();
Remember that your form will be submitted if you not return a boolean value from the function
<input type="submit" id="linkAccountSubmit" onclick="return activeDeLink()" />
function activeDeLink() {
if ($('input[name="SelectedOption"]').val() == "SomeValueToCheck") {
$('.hiddenLink').each(function () {
$(this).removeClass('hiddenLink');
});
return true;
}
else
{
// the condition is false, I dont want submit.
return false;
}
}
Upvotes: 1