I’m calling a jQuery function, but the alert function displays [object Object]. The check value works, but not the passed id value.
Here’s the call to the function taken from the html output:
<td class="myGroups">
<input class="chkSubscribed" type="checkbox" onclick="UpdateSubscription(2)" name="subscribed">
</td>
Here’s the javascsript function:
$(".chkSubscribed").change(function(id) {
alert(id);
var chkd=0;
var groupid=id;
if (this.checked) { chkd=1; }
$.ajax({
type:"POST",
url:"resources/updateSubscribe.php",
data: { group_id: groupid, checkval: chkd },
success: function(){
alert("Account updated!" + "chkval=" + chkd + " id=" + groupid); }
});
});
Thanks for any help!
You’re doing it wrong.
Either you want to call a function or you want to use the change event.
If you want to call a function create a function as follows:
If you want to do it using the change event you can give your input an id of the number you want as follows:
And then your javascript should look as follows: