Richard Young
Richard Young

Reputation: 462

Deselect checkbox if confirm is false

I have a series of checkboxes that uses can click on which will cause a form to submit. Before I submit the form I wasn't them to confirm that's what they want to do. I can't seem to uncheck the box if they choose cancel and I'm not sure what is wrong with the code I'm using. Can anyone help?

<input type="checkbox" name="box_1" id="box_1" value="1" onclick="javascript:if (confirm('Are you sure?')){this.form.submit();}else{document.getElementById('box_1').checked = 'false';};" />

Am I missing something obvious?

Upvotes: 0

Views: 218

Answers (1)

Rakesh_Kumar
Rakesh_Kumar

Reputation: 1442

typo mistake 'false' is a string, which instead should have been simply false

document.getElementById('box_1').checked = false;

Upvotes: 2

Related Questions