I have a text box. I want to take user input from there and pass it to PHP without using submit button. I would prefer a normal button and onclick should pass data to PHP.
Here is something I heard:
- you can call a JS function
onclickand then you can submit the form
from there
But I want to be on the same page after submitting the form. That’s why I didn’t want to submit the form in the first place. But looks like there is no other way.
If anyone knows about the submit method, please, help.
Yes, it is called AJAX. : )
In jQuery, for brevity:
if you want to do it via button click
You can also do it through an A HREF (or submit button, or or something else wacky:
If you want to do it on enter:
Final, site-ready code: