sometime we have some data to send with onclick function , in genral onclick event function works like this:- $('id or class').on("click", function(){ // codes goes here }); here is example of call onclick function on any link, or div:- example -1 <input type="radio" id="1_star<%= val %>" name="rating<%= val %>" value="5" onclick = "set_rating(this,'<%= val %>');"/> <%= vote.hidden_field :rating, value: "", id: "rating_param_#{val}" %> <script type="text/javascript> function set_rating(elem, application_id){ //code goes here $('#rating_param_'+ application_id).get(0).value = rating; }; // ajax request $.ajax({ url: "/admin/dashboard/show_tickets", type: "GET", ...