[thelist] Re: javascript debug (easy)

Tyme newsgroups at no-pun.com
Mon Jun 6 10:51:29 CDT 2005

Well, I am slightly less embarrased by my original ("easy") question, since 
it sparked an actual discussion.

Matt's suggestion did work.  But, I am all about writing more concise code. 
(I suspect that Matt was just correcting my bloated code to work, not 
writing what he himself would have created from scratch.)   In all fairness 
to both Matt and John, I'll write a script that will alternately load one 
version one day, the other the next.  :-)

Okay, I might need a wee bit of help on that alternating load script.  Heh 

>From the ridiculous to the sublime,
----- Original Message ----- 
From: "Brooking, John" <John.Brooking at sappi.com>
To: <thelist at lists.evolt.org>
Sent: Monday, June 06, 2005 10:29 AM
Subject: [thelist] Re: javascript debug (easy)

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)
>return true;
>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

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.


* * Please support the community that supports you.  * *

For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !

More information about the thelist mailing list