Update value dynamically using Select OnChange

HTML part

[code]

<select name="notice_status" id="notice_status" onChange="UpdateStatus(<?=$row->id?>,this.value)">
<option value="Yes" <?=($row->status==’Yes’)?’selected’:”;?>>Yes</option>
<option value="No" <?=($row->status==’No’)?’selected’:”;?>>No</option>
</select>

[/code]

JQuery

[code]

<script type="text/javascript">
function UpdateStatus(id,status)
{
$.ajax({
type: "POST",
url: "update-status.php",
data: {
status: status,
id: id
},
success: function(msg){
if(msg == ‘OK’)
{
alert(‘Status updated successfully’);
}
else
{
alert(msg);
}
}
});
}
</script>

[/code]

The update-status.php file

[code]

error_reporting (E_ALL ^ E_NOTICE);

$post = (!empty($_POST)) ? true : false;

if ($post)
{

$Query = "UPDATE table SET Status = ‘".$_POST[‘status’]."’ WHERE id = ".$_POST[‘id’];

$result = ExecuteQuery($Query);

if($result> 0 )
{
echo ‘OK’;
}
else
{
return mysql_error();
}
}
[/code]

Get Free Email Updates!

Signup now and receive free offers, discounts & coupon codes

I will never give away, trade or sell your email address. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge