Reputation: 91
i have a form with a switch toggle and a input field named userid. When i switch the toggle all works fine and the active.php save the new status in the database. But now i want to have also the userid value to the active.php. The var mode can i get in the active.php via
$mode=$_POST['mode'];
How can i send the userid also to active.php?
Any idea? Thank you
<input type="checkbox" name="<?php echo 'toggle'.$c;?>" id="<?php echo 'toggle'.$c;?>" data-toggle="toggle" data-off="OFF" data-on="ON" checked>
<input id="userid" name="userid" type="hidden" value="<?php echo $userid;?>">
This is the js code
$('#<?php echo 'toggle'.$c;?>').change(function(){
var mode= $(this).prop('checked'),
$.ajax({
type:'POST',
dataType:'JSON',
url:'active.php',
data:'mode='+mode,
success:function(data)
{
var data=eval(data);
message=data.message;
success=data.success;
$("#heading").html(success);
$("#body").html(message);
}
});
});
Upvotes: 0
Views: 38
Reputation: 23
In your ajax parameter, change the data attribute to look as follows:
data: 'mode='+mode + '&userid=' + $('#userid').val ()
Upvotes: 0
Reputation: 4825
Use the &
to separate the two keys.
First of all, retrieve the userid
value
var userid = $('#userid').val();
data:'mode=' +mode+'&userid='+userid,
Upvotes: 1