Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirm() should default to 'CANCEL' button

Status
Not open for further replies.

nvikas

Programmer
Feb 2, 2009
2
US
Hi Team,

When we use a confirm() function in JavaScript. We are prompted with a warning message (with O.K and CANCEL buttons) with the default focus being on 'OK' button.

I want to change it. The default focus should be on the 'CANCEL' button.

Can anybody help me achieve this please?
Thanks.
 
Hi,

I don't think this is possible with javascript. You would have to create your own pop-up form OR in some cases just playing around with the confirm message would help users click the right decision.

Chris
 
JavaScript isn't able to do this.

If you google this, the closest you can get is to use VBScript to override JavaScript's window.confirm function to display a different type of dialog box (the example replaces the Ok/Cancel with Yes/No).

However that only works on Internet Explorer, but not Firefox or pretty much every other browser out there. Those browsers would show a regular Ok/Cancel dialog.

The next closest thing you can do is to pop up a modal window -- use "window.showModalDialog" -- it's like window.open, but the window that opens must be explicitly dismissed before the user can interact with its parent window again. Yahoo Mail uses (used?) these to pop up "are you sure you want to delete all these messages?" dialogs. This way you can customize how the popup dialog looks because it's a regular web page, you can create the text and buttons how you want to.

See:
Or google "showModalDialog"

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Zhris and Kirsle,

Thank you for these inputs. I appreciate your help.
I will try to research more on this and if I find anything more informative, I will jot it down here. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top