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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

confirm() in javascript?

Status
Not open for further replies.

Idee

Programmer
Jul 8, 2003
51
NZ
Hi

I am using confirm(Are you sure you wnat to do it?) in javascript. The dialog box in confirm shows two buttons - Ok and cancel. By default, the focus is on Ok. I want to change the default focus to Cancel. How can I do it?

Thanks
 
Why would you want to do this?

I don't see why the focus would matter on this type of control?



JavaScript Beginner at work :)
 

You can't. You will have to write your own DHTML dialog boxes if you want to do this in JS.

It might be possile in VBScript, although I cannot be 100% sure of this. Ask in the VBScript forum if you decide to look into this.

Hope this helps,
Dan
 
I don't see why the focus would matter on this type of control

One reason that springs instantly to mind: Many of us use the keyboard to shortcut moving the mouse... If we knew that a specific button had focus, we could press Enter or Space as soon as the dialog appeared to action a specific point, without having to check which option was focussed.

Dan
 
After reading several posts on this forum I can confidently say that most internet users are taking the meaning of "laziness" to a new level

JavaScript Beginner at work :)
 
Thanks for all your responses...

I have an alert where accidently I don't want it to say Ok. Only if someone chooses to say 'OK', it should submit.

Is anyone sure that this is not possible with confirm in javascript?
 
Idee,

Change the prompt to its negative sense so that ok means cancel in the original sense.

regards - tsuji
 
Thanks Tsuji for your response but I am not able to understand what you are trying to say.

In my code I say

if(confirm('Are you sure you want to do it?'))
{
formname.submit()
}

When I run this programe, it alerts a dialog box with Ok and Cancel button and Ok is the default button. What I want is to make Cancel as default.

What should I change in above code so that the focus is defaulted to Cancel Button

Thanks
 
Idee,

I meant something as simplistic as this.
[tt]
sprompt="Our policy discourages you to submit this without thinking it all over again.\n"+
"Your action will be blocked by default.\n"+
"If you insist in submitting it, Please cancel this prompt.\n"+
"Else, please confirm you want to have a second though before submitting."
if (confirm(sprompt)) {
formname.submit();
}
[/tt]
- tsuji
 
Correction:
[tt]
if ([red]![/red]confirm(sprompt)) {
formname.submit();
}
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top