Reputation: 27769
How can I pass the value of the radio button below to the copy_select_val() function?
<input type="radio" name="selected_invoice" value="35" onclick="copy_select_val(); return false;">
Upvotes: 0
Views: 2463
Reputation: 9216
JQuery is about being un-intrusive. Meaning, you don't need Javascript in your html elements directly. This said, you can do this:
$("input[name='selected_invoice']:checked").val();
If you are using JQuery you should keep the javascript out of the html.
Upvotes: 2
Reputation: 13428
Like this:
<input type="radio" name="selected_invoice" value="35"
onclick="copy_select_val(this.defaultValue); return false;">
Upvotes: 0
Reputation: 48088
Try this.value
to pass your radio's value to your function :
<input type="radio" name="selected_invoice" value="35"
onclick="copy_select_val(this.value); return false;">
Upvotes: 1
Reputation: 16005
function copy_select_val() {
alert($(this).val());
}
but I'm not user if this will also work on inline handlers like onclick. why dont you just setup a click eventlistener on this button?
Upvotes: 0