Update value dynamically using Select OnChange

0

HTML part

<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>

JQuery

<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>

The update-status.php file

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();
}
}

Get Free Email Updates!

Signup now and receive free offers, discounts & coupon codes

I agree to have my personal information transfered to Mad Mimi ( more information )

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.