tags:

views:

37

answers:

4

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;">
A: 
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?

antpaw
A: 

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;">
Canavar
A: 

Like this:

<input type="radio" name="selected_invoice" value="35"
       onclick="copy_select_val(this.defaultValue); return false;">
gregseth
+1  A: 

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.

Jeremy B.
Understood and will implement!
stef