[thelist] Re: javascript debug (easy)

Brooking, John John.Brooking at sappi.com
Mon Jun 6 09:29:22 CDT 2005


Tyme tried:

>function openOrderForm(){
>
>var agree=confirm("Online ordering is reserved for weekly rentals only.

>Please phone for daily orders. Thank you!");
>
>IF (agree == true)
>
>window.open('https://boomersrentals.c2.ixwebhosting.com/orderform.asp',
'OrderForm','scrollbars=yes,toolbar=no,directories=no,menubar=yes,resiza
ble=yes,status=yes,width=300,height=400,screenX=0,screenY=0,top=0,left=0
');
>
>return true;
>
>ELSE
>
>return false;
>}

Matt suggested:

>function openOrderForm()
>{
>
>    var agree=confirm(...);
>
>    if (agree)
>    {
>        window.open(...);
>    } // end if
>
>    return false;
>}

But Matt, your version doesn't return anything if agree is true. I'd
change the "return false" to "return agree".

Since I'm a sucker for concise code, I'd be tempted to use this
maximally shortened expression:

function openOrderForm() {
   return confirm( ... )
          ? window.open(...)
          : false ;
}

Now why stop there? Create a generic function which takes a prompt and a
URL, and does the same logic for any window you want to open from
anywhere:

function openNewWindow( prompt, url )
   return confirm(prompt) ? window.open(url) : false;
}

You may have noticed that these functions return the handle of the
opened window, or false if no window was opened. I've found it possible
to evaluate this return value in an "if" statement and have the window
handle act as a "true" value, but I'm not sure how supported this is in
the official specs.

- John
-- 


This message may contain information which is private, privileged or confidential and is intended solely for the use of the individual or entity named in the message. If you are not the intended recipient of this message, please notify the sender thereof and destroy / delete the message. Neither the sender nor Sappi Limited (including its subsidiaries and associated companies) shall incur any liability resulting directly or indirectly from accessing any of the attached files which may contain a virus or the like.



More information about the thelist mailing list