Translate

Thursday 18 September 2014

Status Updation using Ajax and selected value echoed in select box

Explaination:
       Onchange the Select box how to update the Status using PHP we can see in this tutorial.
       In this tutorial we will see by using ajax by onchange the status is to update.We can
       how we can  Passing value through ajax and how we can GET that value through ajax all are 
       explaied in this Turorial.I hope this will helpfull for the Developers and Beginers.
       
Note:
      1.onchange="showUpdate(this.value,'<?php echo $row['db_fieldname']; ?>')"-->we can pass               the value to Ajax
    2.  id="txtHint3"--->We have to replace the value 
    3."GET","shippingstatus_update.php?status="+str+"&id="+id,true---->Like this We have to                pass the values to Ajax page
  4.   $id2=$_GET['id'];---------->Get the values
  5.   $shipping=$_GET['status'];--->Get the values  

Form:    

<td >
<select name="shipping" onchange="showUpdate(this.value,'<?php echo $row['booking_number']; ?>')" style="width: 100px;" id="txtHint3" >
<option  <?php if ($row['shipping_status'] == "----" ) echo 'selected'; ?> value="----">----</option>
<option  <?php if ($row['shipping_status'] == "Delivery In Progress" ) echo 'selected'; ?> value="Delivery In Progress">Delivery In Progress</option>
<option <?php if ($row['shipping_status'] == "Delivered" ) echo 'selected'; ?> value="Delivered">Delivered</option>
</select>
</td>   
 

Ajax Script:

<script>
function showUpdate(str,id)
{
var xmlhttp;    
if (str=="")
{
document.getElementById("txtHint3").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","ajax.php?status="+str+"&id="+id,true);
xmlhttp.send();
}
</script>


Ajax.php:


<?php
include("db.php");
$id2=$_GET['id'];
$shipping=$_GET['status'];
mysql_query("update tbl_name set status='$shipping' where booking_number(db_fieldname)='$id2'");
echo "Status updated Successfully";
?>

No comments:

Post a Comment