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 d
Several ways to do that...
It sounds like you're after a non-redirecting solution, so I'd recommend jQuery (it's my fave, but there are plenty other solutions to implementing AJAX) and doing something like the following:
Assume you have a text box and button like this:
Then do something like this
$(document).ready(function () {
$("#btn_send").click(function () {
// Do stuff BEFORE sending... //
callAFunction();
var test = "asdfasdf";
// Send the text to PHP //
$.post("test.php", { input: $("#txt_input").val()},
function(data) {
alert("test.php returned: " + data);
}
);
// Do more stuff after sending.... //
callAnotherFunction();
});
});
I believe that'll get what your after. For more on jQuery and further options with $.post, check here: http://api.jquery.com/jQuery.post/
Hope that helps!