Alex Rivera | Logout

Using JQuery within onClick

Asked 2009-08-13T20:37:44.537
12

Am I allowed to use JQuery within an onClick function?

For example:

<a onclick="my_save_function($("#inputID").val())">
<input type=hidden id="inputID" value="foo">

Such that, when clicked, the anchor tag runs this:

my_save_function(foo);

After a few searches, I couldn't find a similar topic. Thank you for any help.

Edit
Report

1 Answer

5

try this (you'll need an id on the anchor tag):

<a onclick="my_save_function(this.id);">

and in your javascript:

function my_save_function(elid){
    v = $("#"+elid).val();
    // do stuff with v
}
answered 2009-08-13T20:42:18.550

Your Answer