p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Javascript confirm box with just an 'OK' button (http://p2p.wrox.com/showthread.php?t=29495)

crmpicco May 19th, 2005 05:06 AM

Javascript confirm box with just an 'OK' button
 
How can i have a Javascript confirm box with just an 'OK' button and now 'Cancel' button:

Code:

<script language="javascript" type="text/javascript">
//////////////////////////////////////////////////////////////
// Check to see if there is a value inside the                //
// contract id textbox if there isnt then output a message  //
//////////////////////////////////////////////////////////////

function checkFields() {
missinginfo = "";
if (document.form.contract_id.value == "") {
missinginfo += "\n    -  Contract ID";
}

if (missinginfo != "") {
missinginfo = "Please Enter the Contract ID"
document.form.contract_id.focus();
confirm(missinginfo);
return false;
}
else return true;
}


</script>

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

ChrisScott May 19th, 2005 08:08 AM

alert() only has an OK button


crmpicco May 19th, 2005 08:42 AM

i was just looking for a Confirm box because the Alert looked more like an error. is it possible to specify the buttons in a confirm box?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

ChrisScott May 19th, 2005 08:47 AM

afraid not. you'll need to create something custom.


crmpicco May 20th, 2005 04:05 AM

is that JavaScript? Have you got any code that could do this or get me started?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

crmpicco May 20th, 2005 06:31 AM

how can this be done

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

ChrisScott May 24th, 2005 03:49 AM

Sorry Picco, been away a couple of days...

You could do this a number of ways, depending on your target audience. If you only cared about IE, you could use showModalDialog() and have a single button on you dialogue. For a more generic solution you could use a new window / absolutely positioned div etc with the button on it.

Afraid I don't have the code handy, but there a quite a few articles out there on creating modal windows.

HTH,

Chris

crmpicco May 24th, 2005 04:35 AM

thats great, thanks

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

crmpicco May 24th, 2005 04:42 AM

i have this code, but it gives me a Javascript error:
Code:

<html>
   <head>
      <script language="jscript">
         var gobjXDocument = null;

         function Initialize()
         {
            // Save a reference to the XDocument object.
            if (typeof window.dialogArguments == "object")
            gobjXDocument = window.dialogArguments;
         }
      </script>

      <title>A Simple Custom Dialog Box</title>
   </head>

   <body style="BACKGROUND-COLOR: window" onLoad="Initialize()">
      <strong>Click one of the following buttons:</strong>
      <br/>
      <br/>
      <div id="divButtons" tyle="align:center">

         <input id="btnShowAlert" style="WIDTH: 106px; HEIGHT: 24px"
         onclick='gobjXDocument.UI.Alert(gobjXDocument.DOM.xml);'
         type="button" size="21" value="Show Alert"></input>

         <input id="btnCancel" style="WIDTH: 106px; HEIGHT: 24px"
            onclick="window.close();" type="button" size="21"
            value="Cancel"></input>
      </div>
   </body>
</html>

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

ChrisScott May 24th, 2005 05:01 AM

What is XDocument? Are you passing it to this page as an argument in showModalDialog()?

Cheers,

Chris



All times are GMT -4. The time now is 05:40 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.