I've created an AjaxMethod (a very general method, and I'm doing ASP.NET MVC) to get the ID of the item the user clicks on, to add them into the site cart (by adding them to the cookies). The problem is that my Ajax method has one parameter which is used as the ID so I'm creating buttons whose id attribute are the actual product ID and their values are Add to Cart. I've also created a single hidden submit button whose id is the same name as the parameter name in Ajax method and its value depends on the ID of the clicked button.
Click Button ID --Passed into--> Value of submit button
My problem is, I wanna know that is there any way to write a JavaScript/JQuery method and use it in OnClientCLick in the buttons to: get the id of the caller button and then pass it to the value of the submit button.
For example:
// I do not know the ID of the caller
// this method is used like: <button id="1111" OnClientClick="Test()"></button>
function Test() {
var ID = this.id // this did not work
$("#SubmitButton").val(ID)
$("SubmitButton").trigger("click")
}