Ali Hasan
Ali Hasan

Reputation: 1075

How to get the onclick event params with jquery

I have a set of radio buttons which have unique name and id but the value for each radio is same and onclick event, what I want to get is the parameters that are inside the click event of checked radio button on document ready.

<input id="lvCP_CP1_0_rbC_0" type="radio" name="lv$ctrl0$UC1$CP" value="rbC" checked="checked" onclick="SetCPPrice('lvCP_CP1_0_rbCPSelected_0','Total:5','CPID:wrAtPJQGUiuKfptENuMumY/M7utu6gZ3VMRy3KI1P9rNCokUUO','CPPriceUS:75.9878666666667','CPriceEU:107.53');">

Upvotes: 3

Views: 4021

Answers (1)

gdoron
gdoron

Reputation: 150253

var onClickAttribute = $('#lvCP_CP1_0_rbC_0').attr('onclick');

I have no idea why do you need it, but that's the way you can do it.


If you want to split the string to parameters:

var str = $('#lvCP_CP1_0_rbC_0').attr('onclick');   
var params = str.split("SetCPPrice(")[1].split(',');
params[params.length - 1] = params[params.length - 1].replace(');');
console.log(params);​

Live DEMO

Disclaimer: you shouldn't really use this.

Upvotes: 5

Related Questions