I don't know database code, but you would create a separate PHP page that will put that value into the database and do a jQuery.ajax call to that page, passing as either GET or POST the value that you want put into the database. Let's do GET for now (to do POST just change GET to POST and in the javascript change 'get' to 'post'). So, on this separate PHP page, call it - say, setdata.php, we would have:
PHP Code:
<?php
$value = isset($_GET['value'])? $_GET['value'] : '';
//code here to put $value into the database, can test for $value and if $value === '', then either do nothing, delete the record, whatever
//just what you do with $value is up to you, it will be whatever was passed in from the 'top' page, or '' if nothing was passed
?>
Then for your script on the 'top' page:
Code:
<script>
$('input').keyup(function () {
var value = $(this).val();
if (value == '' || isNaN(value)) {
value = '';
}
else if (value > 49) {
$('p').text((value = 'High'));
}
else {
$('p').text((value = 'Low'));
}
$.ajax({
url: 'setdata.php',
cache: false,
data: {value: value},
type: 'get'
});
}).keyup();
</script>
Oh, and I was just looking at this again and wondering what the second .keyup() is for. That does nothing, so could be removed.
Also. with keyup you are checking each time a key goes up. So if they do 100 it's Low, Low, High. Usually change is used instead of keyup. However, change requires that focus be removed from the element. But you can just put a 'Go' button in there right after the text input. It doesn't have to do anything. Just clicking on it will trigger the change event:
Code:
<script>
$('input:text').change(function () {
var value = $(this).val();
if (value == '' || isNaN(value)) {
value = '';
}
else if (val . . .
and:
Code:
<input type='text' value=''/> <input type='button' value='Go'/>
Bookmarks