473,395 Members | 1,613 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,395 software developers and data experts.

javascript confirm delete

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 javascript as an enhancement and not a
requirement
to work.
My question is can I have the html form function normally if the user
has javascript
disabled? It would act as thought there were no javascript code
involved in the
form at all then.

Thanks,
John
Jul 23 '05 #1
2 10100
On Mon, 01 Nov 2004 22:53:57 -0600, neoconwannabe wrote:
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. ... My question is can I have the html form function normally if the user
has javascript disabled?


YEs, by dumping the idea of the pop-up (Won't work on
the 'real world' wide web) and using a second HTML page
instead "You selected the following items for deletion, click
'OK' to proceed, else 'Cancel' to resume without delete"

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #2
neoconwannabe wrote:
Hi, [...] My question is can I have the html form function normally if the user
has javascript
disabled? It would act as thought there were no javascript code
involved in the
form at all then.


Yes.

My reading was that you wanted the delete confirmed if JS was enabled,
but if it wasn't, the form just submits. Here is a script that
confirms when a user checks a box, but doesn't confirm when they
uncheck it. If they cancel the delete action, the box is unchecked.

When the form is submitted, if JS is enabled, the hidden checkbox js is
checked so you know at the server that they have already confirmed the
delete. If they don't have JS enabled, then you know they haven't been
given the prompt because the JS checkbox will not be checked.

I've used a label so you can click on the label text or the checkbox to
check/uncheck it.

Be careful with the reference to the label text. If you put the text
before the checkbox, then "a.nextSibling" will be undefined and an
error will result. You may want to use
"a.parentNode.childNodes[0].data" if the text is before the checkbox,
or "a.parentNode.childNodes[1].data" if you put the text after the
checkbox. I just like nextSibling because it's more concise but you
must put the label text after the checkbox.

*However*, as Andrew advises, if this is for a web site, the confirm
prompt is a bad idea and you should use a summary page to confirm what
the user wants. Yes, it's more laborious, but much more reliable and
if there are a lot of options, they all get confirmed in one go rather
than lots of separate confirms. Consider whether some other method of
confirmation is suitable, like such as a visual prompt in the page
(change the text label to grey or use strike-through or similar).

Cheers, Rob.

<script type="text/javascript">
function doIt(a) {
var b = (confirm('This will delete ' + a.nextSibling.data
+ '\nClick \'OK\' to confirm'));

if(b){
// Do the delete actions
} else {
a.checked=false;
}
}
</script>
<p>Click on a checkbox to delte the option</p>
<form action="">
<input type="checkbox" name="js" style="display: none;">
<label><input type="checkbox" name="opt1"
onclick="if(this.checked)doIt(this);">Option 1</label><br>
<label>Option 2<input type="checkbox" name="opt2"
onclick="if(this.checked)doIt(this);"></label><br>
<input type="reset">
<input type="submit" onclick="this.form.js.checked=true">
</form>
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeremy | last post by:
I have a datagrid that users interact with to add/edit/delete, but before the .aspx submits for the delete action I want to pop up a JavaScript confirm box. If the user clicks OK on that box I...
1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
3
by: JWM | last post by:
Hello: Here is what I am trying to do...... The user clicks on the delete icon, and gets a JavaScript client-side popup to confirm that he wants to delete. I am passing this client-side...
1
by: Muhammad Abdullah | last post by:
Hi am having some problems with the javascript confirm. i have it working fine on one page and it doesnt even pop up at the other. The code on the working page is, private void...
2
by: mark | last post by:
im having issues in creating a javascript confirm option on pressing a delete button in a datagrid - ive tried a few things but nothing seems to work (either crashes or does nothing) my codebehind...
6
by: Jim Heavey | last post by:
Hello, hopefully this is a simple question.. I have the following statemen <asp:Button ID="cmdPPIPDelete" Text="Delete" Runat="server" CssClass="buttonDelete" CommandName="Delete" OnClick="return...
7
by: TJS | last post by:
javascript "confirm" fires after deletion instead of before deletion. how do I get this to stop the processing ? code ================== Sub ShowAlert(ByVal s As string)...
4
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit"...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.