Passing ID into function instead of hard code
Hi,
I manage to get it works by pressing a button and a value will load into a textbox. Here is my code
- <asp:TextBox ID="txtResult" runat="server"></asp:TextBox><br />
- <input id="btn7" type="button" value="7" onclick="PassInput()" />
and my function is
- function PassInput() {
-
- $.ajax({
- type: "POST",
- url: "VB.aspx/GetInput",
- data: '{name: "' + $("#btn7")[0].value + '" }',
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: OnSuccess,
-
- failure: function (response) {
- alert(response.d);
- }
- });
- }
-
- function OnSuccess(response) {
- $("#txtResult").val(response.d);
- }
- function showOutput(data) {
- $("#txtResult").val($("data").val());
- }
But, I do not want to hard code it because I have 10 button , each with different value. How do I pass the ID at
PassInput function and amend line below?
- data: '{name: "' + $("#btn7")[0].value + '" }',
Thanks.