I want to send a variable from a html element to php with ajax. It’s a button, so the value property cannot be used to assign a variable. Is it possible to send it’s id property to a php file with jquery or would there be a better way?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you just want to send the ID field of an element to a server with jQuery, you can do the following:
If you want to store data along with that element, use the
data-property like so:HTML:
Javascript: