I need to get the value inside a textbox without refresh so i can execute an sql statement based on it.
If you're using jQuery, you can use the function .val()
, then .post()
to perform a HTTP post to a PHP page. You can then access the value from the PHP array $_POST
.
Javascript is a client-side language, while PHP is server-sided. The variable can be passed using AJAX, which jQuery .post()
is sufficient for.
//fetch the value of div "input"
var value = $(#'input').val();
//perform a HTTP post
$.post("dest_page.php", {
input: value
});
Then access in PHP.
$input = $_POST['input'];
A really super-easy way is to do a jQuery .load() on an event firing. This might be a button click or on .keyup() event.
$('#txtBox').keyup(function(){
//COLLECT TXTBOX VALUE
var value=$('#txtBox_selector').val()
//SEND VALUE TO SERVER FOR ... WHATEVER YOU WANT TO DO WITH IT
$('#your_selector').html('Loading...').load('path/to/script','value='+value);
})
Hope this helps.