I am trying trying to write a string of multiple values depending on whether specific checkboxes are checked. i.e.
$('#submit').click(function() {
if ($('#box1').attr('checked')) {
$('#MyInput').val('box1 ');
alert('1');
}
if ($('#box2').attr('checked')) {
$('#MyInput').val('box2 ');
alert('2');
}
});
The return I am looking for in this case would be '1 2', however only the second value is written in the input field.
The alerts tell me that both events in the argument are firing. Is there another method for appending values?