Can anyone tell me how to do this? i use button to input data in the text input box. After that i want to click a b
As has been suggested use $.ajax()
The basic syntax is as follows:
$.ajax({
url: '/path/to/file',
type: 'default GET (Other values: POST)',
dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
data: {param1: 'value1'}
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
In your case this can be simplified a little:
$("#add").click(function() {
$.ajax({
url: '/path/to/file',
type: 'POST',
data: {currentTotal: $display.val()},
success: function(result){
// here you will have access to the response from your PHP script
// and can do something with it
}
});
});
In your PHP script, you'll then have access to the value posted, thus:
<?php
$currTot = $POST['currentTotal'];
If you want your JavaScript to receive a return value, you'll have to echo it as the last thing in the PHP file:
<?php
$currTot = $POST['currentTotal'];
// do some processing to obtain $newTotal
echo $newTotal