473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Deselect checkbox if confirm is false

KeredDrahcir
426 256MB
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?

Expand|Select|Wrap|Line Numbers
  1. <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?
Feb 19 '15 #1

✓ answered by gits

since you are setting a javascript property of the dom-element you should set it as a boolean value and not as a string. basically it can be simplified as well like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="box_1" id="box_1" value="1" onclick="
  2.     if (confirm('Are you sure?')) {
  3.         this.form.submit();
  4.     } else {
  5.         this.checked = false;
  6.     };
  7. "/>
  8.  

2 5224
gits
5,390 Expert Mod 4TB
since you are setting a javascript property of the dom-element you should set it as a boolean value and not as a string. basically it can be simplified as well like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="box_1" id="box_1" value="1" onclick="
  2.     if (confirm('Are you sure?')) {
  3.         this.form.submit();
  4.     } else {
  5.         this.checked = false;
  6.     };
  7. "/>
  8.  
Feb 20 '15 #2
KeredDrahcir
426 256MB
That makes sense. Thanks. I'll give it a try and let you know. The reason I was setting it as a string was becuase it hadn't worked so I'd tried something else but I have a feeling it's going to work. Thanks.
Feb 20 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: neoconwannabe | last post by:
Hi, I have an html form with a number of checkboxes that can be checked to delete items. I want to have a javascript alert prompt box to pop up to confirm the delete. I am building my site with...
6
by: Dennis Allen | last post by:
Hi. I got a checkbox in a form. When the form is submitted, an email is generated. In the email text is the field name: on or off. The client doesn't want to see on or off, but yes or no. ...
2
by: Homa | last post by:
Hi, I have a Datagrid that uses as a shopping cart and have a checkbox template column in it. I can't add both OnCheckedChanged Event and onclick client script for it. I want to do two...
0
by: Chris Fink | last post by:
My goal is to have an ASP.NET checkbox server tag with it's autopostback set to true, that when clicked will run the checkbox's CheckedChanged event. However, I would like to try to add a...
2
by: Irfan Akram | last post by:
Hi Guys, I have these series of checkboxes. Whenever any of them are unchecked, I want to display a warning, asking the user to confirm if he really wants to do that. I have added an attribute,...
3
by: enzo | last post by:
I'm using asp.net 2.0 I have a checkbox with server checkedCanged event . I must add a confirm on click event. I have used this : myCheckBox.Attributes.Add("onClick", "return...
4
by: tshad | last post by:
I use popups periodically to my buttons to prevent actions in my pages. When I tried this with a checkbox: DeclineSSN.Attributes.Add("onClick", "if(!confirm('Declining to enter SSN will...
1
by: pleaseexplaintome | last post by:
I have a datagrid with checkboxes and I can check/uncheck the checkboxes to update a database by calling my oncheckchanged function. I would like to add popup asking the users if they are sure...
4
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a cancel argument for cancelling if you want to check or uncheck a checkbox? In the checkChanged event of a checkbox I ask the user if they are sure they want to check/uncheck...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.