I’m having a strange problem with a checkbox on one of my pages. Basically I have a bit of jQuery ( below ) assigned to it so that when it is clicked the fields below fill up with the same info as above ( same as billing info kinda thing ) However when this jQuery is assigned to it the tick fails to fill the checkbox.
I have tried various methods to get the checkbox to tick manually but to no avail, could anyone shed some light on this problem?
$('#sameasbilling').toggle(function() {
//assign value of billing firstname text input to variable 'firstname'
var firstname = $('input[name=billingfirstnames]').val();
//insert value of 'firstname' into delivery text input
$('input[name=deliveryfirstnames]').val(firstname);
$('#sameasbilling').attr("checked", checked);
},function() {
$('input[name=deliveryfirstnames]').val("");
});
The jQuery I have tried ( plus many variants of those two lines ) to get the ticker to work manually is below, neither of them have worked.
$('#sameasbilling').attr("checked", checked);
$('#sameasbilling').prop("checked", true);
Thanks in advance. Dan.
Your use of the
toggle()method is incorrect in this instance, useclick()instead. Try this: