Hi guys I need a help here,
I’m trying to use Ajax to update the column of the table in the database with combobox without a submit button, by the way it update the column finely but unfortunately the column data is erased to 0 when a webpage is refreshed.
May aim is to maintain the column’s data until is updated again.
Any help will be appreciated,
Here is the code
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","?q="+str,true);
xmlhttp.send();
}
}
</script>
<?php include("idadi.php"); ?>
<form style="height:0.5px;">
<label style="height:6px;">
<select name="Idadi" style="width:65px;" onchange="showUser(this.value)">
<option value="0" <?php if($Idadi=="0") { echo "selected"; } ?>>0</option>
<option value="1" <?php if($Idadi=="1") { echo "selected"; } ?>>1</option>
<option value="2" <?php if($Idadi=="2") { echo "selected"; } ?>>2</option>
<option value="3" <?php if($Idadi=="3") { echo "selected"; } ?>>3</option>
<option value="4" <?php if($Idadi=="4") { echo "selected"; } ?>>4</option>
<option value="5" <?php if($Idadi=="5") { echo "selected"; } ?>>5</option>
<option value="6" <?php if($Idadi=="6") { echo "selected"; } ?>>6</option>
</select>
</form>
idadi.php file
<?php
include('dbconnection.php');
$q = intval($_GET['q']);
$idadiquery="update `itemreg` set `Idadi` = '$q'";
$idadiresult = mysql_query($idadiquery);
?>