On my ASP.Net/C# page, I have textboxes to enter in data for a transaction. I am using a payment API to accept credit card transactions. It comes with some sample code in jQuery, which I am editing (see below). The section of my code that says "data" is where I need help. I want to get the text from each asp.net textbox. My current idea below, such as $(TxtAction).val() does not actually pull the textbox value as I want. So I need some help on how I can get the text from the asp.net textboxes. I'd actually prefer to get the values in C# and then somehow send those values to my jQuery code or even just have everything in C# instead of jQuery. Any advice/help is appreciated.
$(document).ready(function () {
'Send a Credit Card Transaction'
var settings = {
"url": "URLHERE",
"method": "POST",
"headers": {
"X-Forte-Auth-Organization-Id": "IDHERE",
"Authorization": "CODEHERE",
"Content-Type": "application/json",
},
"data": "{\r\n \"action\":" + $(TxtAction).val() + ",\r\n \"authorization_amount\":" + $(TxtAuthorizationAmount).val() + ",\r\n \"subtotal_amount\":" + $(TxtSubtotalAmount).val() + ",\r\n \"billing_address\":{\r\n \"first_name\":" + $(TxtFirstName).val() + ",\r\n \"last_name\":" + $(TxtLastName).val() + ",\r\n \"card\":{\r\n \"card_type\":" + $(TxtCardType).val() + ",\r\n \"name_on_card\":" + $(TxtCardName).val() + ",\r\n \"account_number\":" + $(TxtCardNumber).val() + ",\r\n \"expire_month\":" + $(TxtCardExpireMonth).val() + ",\r\n \"expire_year\":" + $(TxtCardExpireYear).val() + ",\r\n \"card_verification_value\":" + $(TxtCardVerificationCode).val() + ",\r\n }\r\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
})
I'd actually prefer to get the values in C#. no no! You really don't want to do that! But I think you are just missing a #.$("#TxtAction").val()