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

Alert() useing yes and no buttons?

Status
Not open for further replies.

Ovatvvon

Programmer
Joined
Feb 1, 2001
Messages
1,514
Location
US
Hi,
In vbscript programming, you can create an alert (msgbox()) that can have an ok button, yes no buttons, ok and cancel buttons, etc. etc. etc.

Is there a way to get yes no buttons in javascript to confirm if someone wants to do somthing or not. And if so, how can you verify which selection they made.

Thanks in advance,
-Ovatvvon :-Q
 
Hi ovatvvon,

You can use the following:

check = confirm("some yes/no question")

This generates an alert with an ok and a cancel button.
If ok is pressed, check equals true otherwise, ofcourse, false.

Don't think you can change the buttons to something else.

Gtz,

Kristof
 
And you can also use it in a conditional...

if confirm('Are you really really really sure?')
//do something
else
//do something else

penny.gif
penny.gif
 
Or if you really really wanted, you could create a layer that holds a table that you designed yourself to look just like an alert box. This way you can customize the graphic as well as what the buttons say. You could then center it and if you really wanted to you could have it scroll with the user.
 
Thank you kristof and link9. It works!

Mithrilhall,
If I understand you correctly, you are saying to use a page to confirm if they want to do an action...I know I could do that, it's not the point of it looking like an alert / msgbox...it's the point of confirming what the user wants, without having to make a trip to the server for another page, then get the confirmation and make another trip to go to the end page and execute whatever the thing was. I want form validation on the same page with 0 trips to the server until execution time.

If I misunderstood you, please let me know.

Thanks again all.
-Ovatvvon :-Q
 
Hello Ovatvvon!

Something an addition to what kristof and link9 said. Sometimes it's useful to make script shorter without any checking IF...ELSE. For example your user want to submit the form and when he\she presses Submit you show your Confimation. It looks like this:

<form onSubmit=&quot;return Confirm('Are you really really sure?\n Submit now?')&quot;>

If user selects OK it submits the form if not doesn't. So we use return function. And no any additional chechking IF...ELSE...

Hope it'll help someone!

Good Luck!
 
Hey Ovatvvan, I think what Mithrilhall was saying was make a DHTML layer that is hidden on the page when it loads, but gets invoked on the client via your script, so it has the appearance of a popup, but it's essentially just HTML layer that is hidden until you call it. It stays on the server and the buttons can call validation routines or whatever you want them to, all still on the client. I personally wouldn't do it that way for fear of browser compatibility issues, but that would be a nice way to have completely controllable &quot;pop-ups&quot;.

-Scott
 
scotth4v pretty much summed up what I was trying to say. I recently did something like what I suggested minus the box scrolling with the user and I got it to work in Netscape 4.7, Opera 5.12, Netscape 6, IE 5, and IE 5.5 so I'm not sure if browser compatibility would be an issue.

I'm definitely not a JavaScript expert (actually far from it) but it sounds like what I suggested would be feasible for what you are trying to accomplish but I could be wrong....It wouldn't be a first. 8-)
 
For the look and feel of the site, I should use a pop-up. Thank you sveta, that is exactly what I need it for (form).

Jolly Good work mates!
-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top