473,795 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10119
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.nextSibl ing" will be undefined and an
error will result. You may want to use
"a.parentNode.c hildNodes[0].data" if the text is before the checkbox,
or "a.parentNode.c hildNodes[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.d ata
+ '\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(thi s.checked)doIt( this);">Option 1</label><br>
<label>Option 2<input type="checkbox" name="opt2"
onclick="if(thi s.checked)doIt( this);"></label><br>
<input type="reset">
<input type="submit" onclick="this.f orm.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
2168
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 want the page to be submited and to delete the item(s) from the grid, if the user clicks CANCEL I don't want the page to do a postback. So far I have everything working except the JavaScript confirm box (in other words the delete just happens
1
5079
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 they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf) System.Web.HttpContext.Current.Response.Write("if (confirm('Are you sure you want to...
3
1895
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 function a contactID. Then, I want to send the result of this confirm (true|false) to a server-side VBScript function, along with the contactID. The VBScript function will then perform a delete in the database for the specified contactID.
1
2651
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 Page_Load(object sender, System.EventArgs e) { if(! Page.IsPostBack)
2
1514
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 is laid out like this :- Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand 'edit from datagrid
6
2264
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 confirm('Please Confirm You Want To Delete Record')"></asp:Button Each time I navigate to this page, I get a compile error of "CS1041 Identifier expected, return is a keyword" Iif I take out the javascript, then I have no errors when I...
7
2024
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) RegisterClientScriptBlock("CSP-showconfirm-function", _ "<s"+"cript language=""JavaScript"">" & vbCrLf & _
4
10025
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" and a "delete" node. I have the functionality of the edit and delete working fine, my issue is now however that I cannot seem to find a way to add an "onclick" event that fires a confirm box. I've tried this method.. treenode.Text = "<a...
6
2529
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 get response from a Confirm() popup window to uncheck all server-side checkboxes placed in a panle of a web user control? I am using ASP.Net 2.0, Thanks. Need info...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.