Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

JavaScript_Official · JavaScript . AJAX . ActionScript

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 7407
  • Category: JavaScript
  • Founded: Aug 27, 1998
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Messages

Advanced
Messages Help
Messages 14231 - 14261 of 16942   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#14231 From: Bolon <simbesar@...>
Date: Fri Sep 1, 2006 10:29 am
Subject: Load Excel File
simbesar
Send Email Send Email
 
Can Java Script load the worksheets from excels file, because that is a long
formula

#14232 From: "Nick" <nickj6282@...>
Date: Fri Sep 1, 2006 9:42 pm
Subject: Re: Load Excel File
nickj6282
Send Email Send Email
 
--- In JavaScript_Official@yahoogroups.com, Bolon <simbesar@...> wrote:
>
> Can Java Script load the worksheets from excels file, because that
is a long formula
>

You could export your Excel file as XML and use JavaScript to parse it.

-Nick

#14233 From: "Paul Cowan" <dagda1@...>
Date: Sun Sep 3, 2006 11:59 am
Subject: Currency Format
dagda6000
Send Email Send Email
 
Hi all,
How can I format the following into a currency value or at least a decimal with
a precision of 2 points:

2145.6000000000003

ThanksPaul
dagda1@...

[Non-text portions of this message have been removed]

#14234 From: "Jonas Raoni" <jonasraoni@...>
Date: Sun Sep 3, 2006 12:59 pm
Subject: Re: [JavaScript] Currency Format
jonasraoni
Send Email Send Email
 
On 9/3/06, Paul Cowan <dagda1@...> wrote:
> Hi all,
> How can I format the following into a currency value or at least a decimal
with a
> precision of 2 points:

<URL:http://www.jsfromhell.com/number/fmt-money>

Or

alert((+12345.6789.toFixed(2)).toLocaleString());

The second is obviously better, but it will use the current currency
configuration of the computer.


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

#14235 From: "Alan K Baker" <alan@...>
Date: Sat Sep 2, 2006 7:31 pm
Subject: My email evaluation.
wurlitzerwilly
Send Email Send Email
 
x-posted because no reply from other group.

Hi all.

I'm rather new to Javascript, although I've done a lot of programming
in past years, in other languages.

Below is some code I have in development. I haven't included the
calling HTML which is a fairly simple form with Print, Clear and
Close buttons, except for the Print Button routine.

It's a bit long winded with all the Else statements, but that's so it
starts with the first form field and ripples through to the last,
validating each field as it runs.
It all works fine except for the email address validation. This is OK
if the field is empty or if the field is invalid - it either drops
thru when empty, or issues an appropriate warning when the address is
bad. The problem comes when the address is valid - the routine should
drop thru to the next field validation, but doesn't! It just
disappears into a black hole! All of the fields can still be altered
and re-validated and if the email field is cleared or made invalid,
the routine works again as expected.

I guess I've probably got a brace misplaced, or misunderstood the
rules for nesting.

I do hope someone can point me in the right direction.

**********************************************************************
*********************

<script language="JavaScript">
  <!-- Hide script from old browsers

  emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})
+$/            //for email address validation

function empty (field,warning)
{                                                //if mandatory field
is empty, warn user
  alert("You must fill in your "+warning+"!")
  field.focus()
  field.select()
                                             }

function printdoc(text)
{                                                          //validate
entire document field by field, then call printer
  if (AWSform.Name.value == "") {
   empty(AWSform.Name,"name")
                                                }
  else {
   if (AWSform.House.value == "") {
   empty(AWSform.House,"address")
                                                  }
    else {
     if (AWSform.City.value == "") {
     empty(AWSform.City,"town/city")
                                                }
     else {
       if (AWSform.County.value == "") {
       empty(AWSform.County,"county")
                                                       }
      else {
         if (AWSform.Zip.value == "") {
        empty(AWSform.Zip,"postcode")
                                                   }
       else {
         if (AWSform.Email.value != "")
{                                      //Houston we have a problem!!!
   if (!emlchk.test(AWSform.Email.value))
{                               //************************************
**************
       alert ("Invalid email
address!")                                          //This works fine
until the email check is true
    AWSform.Email.focus
()                                                     //then it
disappears into a 'black hole'
    AWSform.Email.select
()                                                    //**************
************************************
                                           }
          }
       else {
           if (AWSform.Age.value == "") {
           empty(AWSform.Age,"age")
                                                      }
        else {
           if (AWSform.Plage.value == "") {
           empty(AWSform.Plage,"playing age")
                                                         }
         else {
   text=document
   print(text)
                }
              }
            }
          }
         }
        }
       }
      }
     }
  // End hiding script from old browsers -->
</script>

HTML
  <input name="Print" type="button" value="Print form"
onclick="printdoc()">

**********************************************************************
*********************

Regards,

Alan.
www.theatreorgans.co.uk
Admin: 2nd Touch, SSusers and UKShopsmiths Groups
Editor Adur & Sussex Federation NHW Web Pages
Theatre Pipe Organ Builder
ShopSmith V520
Flatulus Antiquitus

#14236 From: mike_austin23
Date: Sun Sep 3, 2006 4:53 am
Subject: Needing help setting up a form
mike_austin23
 
Hello. My name is Mike. My wife and I are web site designers and are
needing some help setting up something that is probably easy for
most of you.

We are needing two things:

1. A form so that visitors to our web site can submit their first
name and email address for the purpose of signing up for a monthly
newsletter. As well as the ability of unsubscribing to it.

2. A form (for a different site) so that possible customers can
email us their contact information (name, email address, phone
number, and details of their comments/questions). I know we could
simply post the email address and let them worry about sending the
information, but it would be more benefitial for them to fill the
form out, click submit, and go on about their business.

Can someone help?

Thanks!

#14237 From: Eugene Donaghy <eugene.donaghy@...>
Date: Sun Sep 3, 2006 8:41 pm
Subject: cookie problem
eugene_donaghy
Send Email Send Email
 
hi having problems with this code

function alert1()
{
    if (document.cookie = "")
    {
       if (confirm("       ***WARNING*** \n Some of these jokes MAY be
offensive \n If you do not wish to be offended \n Please Press Cancel to
return"))
    {
       expireDate = newDate;
       expireDate.setDay(expireDate.getDay()+1);
       document.cookie="allow";
    }
    else
    {
       expireDate = newDate;
       expireDate.setDay(expireDate.getDay()+1);
       document.cookie="disallow";
       history.go(-1);
    }
    }
    if (document.cookie="allow")
    {
    }
    else
    {
       alert("Sorry you are not allowed to view jokes");
       history.go(-1);
    }
}

i had a pop up to confirm the user wanted to access jokes but it popped
up every time i wanted to access a joke page but now it wont pop up :(
please advise how i can get it working

Eugene

#14238 From: Miguel Rodrķguez <miguel.rdz@...>
Date: Sun Sep 3, 2006 12:47 pm
Subject: Re: [JavaScript] Currency Format
Mianrogo
Send Email Send Email
 
Use the method toFixed(x) or the method toPrecision(x).

In this link you can get more information about this topic:

http://www.pageresource.com/jscript/j_a_03.htm

good luck.

On Sun, 03 Sep 2006 06:59:16 -0500, Paul Cowan <dagda1@...> wrote:

> Hi all,
> How can I format the following into a currency value or at least a
> decimal with a precision of 2 points:
> 2145.6000000000003
> ThanksPaul
> dagda1@...
>
> [Non-text portions of this message have been removed]
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

#14239 From: "David Smart" <smartware@...>
Date: Mon Sep 4, 2006 8:11 am
Subject: Re: [JavaScript] My email evaluation.
smartware_co...
Send Email Send Email
 
Your habit of putting {} after EVERY "if" and "else" is getting you into
trouble here, I think.  At the very least, you should write "else if"
without a {} for the else.  And the "else if" should be on the same line,
not two.  Additionally, I suspect that you are not indenting the code around
the problem area correctly.  Recasting your code:

.function printdoc(text)
.{ //validate entire document field by field, then call printer
.  if (AWSform.Name.value == "") {
.   empty(AWSform.Name,"name")
.  }
.  else if (AWSform.House.value == "") {
.   empty(AWSform.House,"address")
.  }
.  else if (AWSform.City.value == "") {
.    empty(AWSform.City,"town/city")
.  }
.  else if (AWSform.County.value == "") {
.    empty(AWSform.County,"county")
.  }
.  else if (AWSform.Zip.value == "") {
.    empty(AWSform.Zip,"postcode")
.  }
.  else if (AWSform.Email.value != "") {   //Houston we have a problem!!!
.    if (!emlchk.test(AWSform.Email.value)) {
.
//**************************************************
.      alert ("Invalid email address!")    //This works fine until the email
check is true
.      AWSform.Email.focus ()              //then it disappears into a
'black hole'
.      AWSform.Email.select ()
//**************************************************
.    }
.  }
.  else if (AWSform.Age.value == "") {
.    empty(AWSform.Age,"age")
.  }
.  else if (AWSform.Plage.value == "") {
.    empty(AWSform.Plage,"playing age")
.  }
.  else {
.    text=document
.    print(text)
.  }
.}

(note that I have put a full-stop at the beginning of each line to attempt
to keep the indents correct for the e-mail.)

If you put your opening curly brackets at the end of the if statement lines,
you MUST align your closing curly brackets with the start of that line, not
with the opening curly bracket.  Doing otherwise will hide that they are
actually doing and cause problems like you have here.

Now that the indenting is consistent, looking at the code immediately shows
that you have treated the e-mail address differently from all the others.
Your normal test is "is it empty?".  If it is, you produce the error message
and that's the end of the processing.  For e-mail you ask "is it
non-empty?".  If it is, you do something else, then that's the end of the
processing.

So a legal e-mail address will be non-empty and will never get to the print
statement.  Certainly not what you want.

Is an empty e-mail address legal?  If it isn't then you need to do an
"empty" test in the same way as the others.  Then you need to do another
check (not nested) to see if it is legal.

If an empty e-mail address is legal, then you need to ask a double question
(i.e. is it non-empty and is it illegal).  Combine the two parts of the test
with &&.

Rather than nesting if's, you should look at returning early from the
routine when there is a problem.

.function printdoc(text)
.{ //validate entire document field by field, then call printer
.  if (AWSform.Name.value == "") {
.   empty(AWSform.Name,"name");
.   return;
.  }                                               }
.  if (AWSform.House.value == "") {
.    empty(AWSform.House,"address");
.    return;
.  }
.  if (AWSform.City.value == "") {
.    empty(AWSform.City,"town/city");
.    return;
.  }
.  if (AWSform.County.value == "") {
.    empty(AWSform.County,"county");
.    return;
.  }
.  if (AWSform.Zip.value == "") {
.    empty(AWSform.Zip,"postcode");
.    return;
.  }
.  if (AWSform.Email.value != "") {   //Houston we have a problem!!!
.    if (!emlchk.test(AWSform.Email.value)) {
.
//**************************************************
.      alert ("Invalid email address!");   //This works fine until the email
check is true
.      AWSform.Email.focus ();             //then it disappears into a
'black hole'
.      AWSform.Email.select ();
//**************************************************
.      return;
.    }
.  }
.  if (AWSform.Age.value == "") {
.    empty(AWSform.Age,"age");
.    return;
.  }
.  if (AWSform.Plage.value == "") {
.    empty(AWSform.Plage,"playing age");
.    return;
.  }
.  text=document;
.  print(text);
.}

Better yet, you should move the validation code into a validation function:

.function validate ()
.{
.  if (AWSform.Name.value == "") {
.    empty(AWSform.Name,"name");
.    return false;
.  }                                               }
.  if (AWSform.House.value == "") {
.    empty(AWSform.House,"address");
.    return false;
.  }
.  if (AWSform.City.value == "") {
.    empty(AWSform.City,"town/city");
.    return false;
.  }
.  if (AWSform.County.value == "") {
.    empty(AWSform.County,"county");
.    return false;
.  }
.  if (AWSform.Zip.value == "") {
.    empty(AWSform.Zip,"postcode");
.    return false;
.  }
.  if (AWSform.Email.value != "") {   //Houston we have a problem!!!
.    if (!emlchk.test(AWSform.Email.value)) {
.
//**************************************************
.      alert ("Invalid email address!");   //This works fine until the email
check is true
.      AWSform.Email.focus ();             //then it disappears into a
'black hole'
.      AWSform.Email.select ();
//**************************************************
.      return false;
.    }
.  }
.  if (AWSform.Age.value == "") {
.    empty(AWSform.Age,"age");
.    return false;
.  }
.  if (AWSform.Plage.value == "") {
.    empty(AWSform.Plage,"playing age");
.    return false;
.  }
.  return true;
.}
.
.function printdoc(text)
.{
.  if (validate ()) {
.    text=document;
.    print(text);
.  }
.}

Last - and certainly not least - please use semicolons correctly at the end
of statements.  You will see that I have inserted them.

Regards, Dave S

----- Original Message -----
From: "Alan K Baker" <alan@...>
To: <JavaScript_Official@yahoogroups.com>
Sent: Sunday, September 03, 2006 5:31 AM
Subject: [JavaScript] My email evaluation.


> x-posted because no reply from other group.
>
> Hi all.
>
> I'm rather new to Javascript, although I've done a lot of programming
> in past years, in other languages.
>
> Below is some code I have in development. I haven't included the
> calling HTML which is a fairly simple form with Print, Clear and
> Close buttons, except for the Print Button routine.
>
> It's a bit long winded with all the Else statements, but that's so it
> starts with the first form field and ripples through to the last,
> validating each field as it runs.
> It all works fine except for the email address validation. This is OK
> if the field is empty or if the field is invalid - it either drops
> thru when empty, or issues an appropriate warning when the address is
> bad. The problem comes when the address is valid - the routine should
> drop thru to the next field validation, but doesn't! It just
> disappears into a black hole! All of the fields can still be altered
> and re-validated and if the email field is cleared or made invalid,
> the routine works again as expected.
>
> I guess I've probably got a brace misplaced, or misunderstood the
> rules for nesting.
>
> I do hope someone can point me in the right direction.
>
> **********************************************************************
> *********************
>
> <script language="JavaScript">
> <!-- Hide script from old browsers
>
> emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})
> +$/            //for email address validation
>
> function empty (field,warning)
> {                                                //if mandatory field
> is empty, warn user
> alert("You must fill in your "+warning+"!")
> field.focus()
> field.select()
>                                            }
>
> function printdoc(text)
> {                                                          //validate
> entire document field by field, then call printer
> if (AWSform.Name.value == "") {
>  empty(AWSform.Name,"name")
>                                               }
> else {
>  if (AWSform.House.value == "") {
>  empty(AWSform.House,"address")
>                                                 }
>   else {
>    if (AWSform.City.value == "") {
>    empty(AWSform.City,"town/city")
>                                               }
>    else {
>      if (AWSform.County.value == "") {
>      empty(AWSform.County,"county")
>                                                      }
>     else {
>        if (AWSform.Zip.value == "") {
>       empty(AWSform.Zip,"postcode")
>                                                  }
>      else {
>        if (AWSform.Email.value != "")
> {                                      //Houston we have a problem!!!
>  if (!emlchk.test(AWSform.Email.value))
> {                               //************************************
> **************
>      alert ("Invalid email
> address!")                                          //This works fine
> until the email check is true
>   AWSform.Email.focus
> ()                                                     //then it
> disappears into a 'black hole'
>   AWSform.Email.select
> ()                                                    //**************
> ************************************
>                                          }
>         }
>      else {
>          if (AWSform.Age.value == "") {
>          empty(AWSform.Age,"age")
>                                                     }
>       else {
>          if (AWSform.Plage.value == "") {
>          empty(AWSform.Plage,"playing age")
>                                                        }
>        else {
>  text=document
>  print(text)
>               }
>             }
>           }
>         }
>        }
>       }
>      }
>     }
>    }
> // End hiding script from old browsers -->
> </script>
>
> HTML
> <input name="Print" type="button" value="Print form"
> onclick="printdoc()">
>
> **********************************************************************
> *********************
>
> Regards,
>
> Alan.
> www.theatreorgans.co.uk
> Admin: 2nd Touch, SSusers and UKShopsmiths Groups
> Editor Adur & Sussex Federation NHW Web Pages
> Theatre Pipe Organ Builder
> ShopSmith V520
> Flatulus Antiquitus
>
>
>
>
>
>
>
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
>
>
>
>
>
>
>

#14240 From: "David Smart" <smartware@...>
Date: Mon Sep 4, 2006 8:18 am
Subject: Re: [spammed] [JavaScript] cookie problem
smartware_co...
Send Email Send Email
 
The first and third IF statements have a single equals sign instead of a
double equals sign.

Regards, Dave S

----- Original Message -----
From: "Eugene Donaghy" <eugene.donaghy@...>
To: "js" <JavaScript_Official@yahoogroups.com>
Sent: Monday, September 04, 2006 6:41 AM
Subject: [spammed] [JavaScript] cookie problem


> hi having problems with this code
>
> function alert1()
> {
>   if (document.cookie = "")
>   {
>      if (confirm("       ***WARNING*** \n Some of these jokes MAY be
> offensive \n If you do not wish to be offended \n Please Press Cancel to
> return"))
>   {
>      expireDate = newDate;
>      expireDate.setDay(expireDate.getDay()+1);
>      document.cookie="allow";
>   }
>   else
>   {
>      expireDate = newDate;
>      expireDate.setDay(expireDate.getDay()+1);
>      document.cookie="disallow";
>      history.go(-1);
>   }
>   }
>   if (document.cookie="allow")
>   {
>   }
>   else
>   {
>      alert("Sorry you are not allowed to view jokes");
>      history.go(-1);
>   }
> }
>
> i had a pop up to confirm the user wanted to access jokes but it popped
> up every time i wanted to access a joke page but now it wont pop up :(
> please advise how i can get it working
>
> Eugene
>
>
>
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
>
>
>
>
>
>

#14241 From: "Alan K Baker" <alan@...>
Date: Mon Sep 4, 2006 10:51 am
Subject: Re: [JavaScript] My email evaluation.
wurlitzerwilly
Send Email Send Email
 
David.

Thank you so much. I am now a happy bunny! :-)

Strangely enough I had re-written the code just after I submitted the piece
you've just seen, just because I didn't like the messy pile of "}" at the end of
the script, and I had put in a pile of "returns" as you suggest. Of course that
does make the code easier to read and I do take your point about correct
indentation. My only excuse is that of the few book on JavaScript that I own,
none have correctly addressed the problems of correct indentation.

As far as the semicolons are concerned, some books have said use them and others
have said that they aren't necessary. I'm afraid I erred on the side of
laziness! :-)

As for a "validate" subroutine, I quite agree. I tend to write straight line
code, then look for ways of tidying it up, obviously looping or subroutining
where there are many repeats. Again my excuse is that this code is unfinished
and will see a great tidy-up transformation before being let loose.

Now, as far as my major problem is concerned, I apologise, I should have made it
clear that an "empty" email address is legal, as will be things like home and
mobile phone numbers, dietary requirements etc. The validations are there in
case the field is filled in. So, I do indeed need two checks using &&. I've
re-written the code and it all now steps smartly into line. <g>

Thanks again for a quick response and "bailing me out".

Regards,

Alan.
www.theatreorgans.co.uk
Admin: 2nd Touch, SSusers and UKShopsmiths Groups
Editor Adur & Sussex Federation NHW Web Pages
Theatre Pipe Organ Builder
ShopSmith V520
Flatulus Antiquitus

   ----- Original Message -----
   From: David Smart
   To: JavaScript_Official@yahoogroups.com
   Sent: Monday, September 04, 2006 9:11 AM
   Subject: Re: [JavaScript] My email evaluation.


   Your habit of putting {} after EVERY "if" and "else" is getting you into
   trouble here, I think.  At the very least, you should write "else if"
   without a {} for the else.  And the "else if" should be on the same line,
   not two.  Additionally, I suspect that you are not indenting the code around
   the problem area correctly.  Recasting your
code:...............................

   If you put your opening curly brackets at the end of the if statement lines,
   you MUST align your closing curly brackets with the start of that line, not
   with the opening curly bracket.  Doing otherwise will hide that they are
   actually doing and cause problems like you have here.........................

   Now that the indenting is consistent, looking at the code immediately shows
   that you have treated the e-mail address differently from all the others.
   Your normal test is "is it empty?".  If it is, you produce the error message
   and that's the end of the processing.  For e-mail you ask "is it
   non-empty?".  If it is, you do something else, then that's the end of the
   processing.........................................

   So a legal e-mail address will be non-empty and will never get to the print
   statement.  Certainly not what you want.

   Is an empty e-mail address legal?  If it isn't then you need to do an
   "empty" test in the same way as the others.  Then you need to do another
   check (not nested) to see if it is legal.

   If an empty e-mail address is legal, then you need to ask a double question
   (i.e. is it non-empty and is it illegal).  Combine the two parts of the test
   with &&.

   Rather than nesting if's, you should look at returning early from the
   routine when there is a problem.......................................

   Better yet, you should move the validation code into a validation
function:................

   .Last - and certainly not least - please use semicolons correctly at the end
   of statements.  You will see that I have inserted them.


[Non-text portions of this message have been removed]

#14242 From: "David Smart" <smartware@...>
Date: Mon Sep 4, 2006 9:32 pm
Subject: Re: [JavaScript] My email evaluation.
smartware_co...
Send Email Send Email
 
Alan

> Thank you so much. I am now a happy bunny! :-)

Glad to hear it.

> ... and I had put in a pile of "returns" as you suggest.

In a way, they're not "correct", in that they are like the dreaded "goto's",
but in some situations they really clean up the code - enhancing readability
rather than detracting from it.

> Of course that does make the code easier to read and I do
> take your point about correct indentation. My only excuse
> is that of the few book on JavaScript that I own, none have
> correctly addressed the problems of correct indentation.

That's a concern, of course.  They really should discuss style to some
extent.  Consistent and logical (not so much "correct") indentation is so
important.  In general, JavaScript is indented the same was as Java and C,
so there will be style guides out there.  But of course, they'll all
conflict.  :-)

Perhaps the biggest variation is with those who put the { on its own line,
lined up with the beginning of the IF, etc, and those who put the { at the
end of the line that "owns" it, and then line up the } with the beginning of
the IF rather than the { itself.  Coming to C/Java/JavaScript via Pascal and
Algol (that shows my age), I put the { on its own line, but many don't.

Another big point of difference is where to put spaces inside statements -
particularly around parentheses.  There are many personal styles for this -
and none are "right".  The important thing is to go for maximum readability
in your own eyes, and to use a consistent style.

> As far as the semicolons are concerned, some books have
> said use them and others have said that they aren't necessary.
> I'm afraid I erred on the side of laziness! :-)

I would cheerfully strangle the authors who say that they aren't necessary.
This is not very responsible.  They should be teaching the language, and
semicolons are part of the language.

On rare occasions, I have seen a JavaScript interpreter get confused because
of a missing parenthesis.  But more importantly, semicolons allow the
interpreter to stop syntax scanning at the end of a statement.  Otherwise,
it'll need to overshoot and then back up, which has got to be slower.

> As for a "validate" subroutine, I quite agree. I tend to write
> straight line code, then look for ways of tidying it up, obviously
> looping or subroutining where there are many repeats. Again
> my excuse is that this code is unfinished and will see a great
> tidy-up transformation before being let loose.

Shudder.  Try to get into the habit of working the other way.  This way
leads to incomplete or incorrect or hard to debug code.

Learn to write essentially top down.  I would have approached this bit of
code by writing

.function validate ()
.{
.  return true;
.}
.
.function printdoc (text)
.{
.  if (validate ())
.  {
.    text = document;
.    print (text);
.  }
.}

That would let me check out the print function first, then fill in the
validation later.

Subroutines/functions should not be considered as a way of "tidying up"
code - they should be the structure that provides a logical flow to the
parent module.  This means that the main flow of the code is readable right
from the start and is clearly correct, then you can fill in the details in
the underlying routines later.

> Now, as far as my major problem is concerned, I apologise, I
> should have made it clear that an "empty" email address is legal,
> as will be things like home and mobile phone numbers, dietary
> requirements etc. The validations are there in case the field is
> filled in. So, I do indeed need two checks using &&. I've
> re-written the code and it all now steps smartly into line. <g>

No need to apologise on this, specifications always have missing "gems" of
information.  :-)

You're not the first to get trapped by this code sequence.  (And I've had my
occasions too.)  Depending on where the e-mail check routine came from and
what else it's being used for, another approach would be to pass the field
to it, empty or not, and have it consider an empty field as acceptable.
Which way to go depends on what looks best to you - and possibly on what you
had for breakfast that morning.

> Thanks again for a quick response and "bailing me out".

Pleaseure.

> Alan
> www.theatreorgans.co.uk

Regards, Dave S

Principal Horn, Assistant Conductor
Manly District Band
manlybrassband@...
http://members.optushome.com.au/djsmart/ManlyBand/

#14243 From: Jon Stephens <jon@...>
Date: Tue Sep 5, 2006 12:47 am
Subject: Re: My email evaluation
jdwayside
Send Email Send Email
 
> My email evaluation.
>     Posted by: "Alan K Baker" alan@... wurlitzerwilly
>     Date: Mon Sep 4, 2006 12:20 am (PDT)
>
> x-posted because no reply from other group.

(??? Doesn't tell us anything - there are heaps of other mailing lists
out there.)

>
> Hi all.
>
> I'm rather new to Javascript, although I've done a lot of programming
> in past years, in other languages.
>
> Below is some code I have in development. I haven't included the
> calling HTML which is a fairly simple form with Print, Clear and
> Close buttons, except for the Print Button routine.
>
> It's a bit long winded with all the Else statements, but that's so it
> starts with the first form field and ripples through to the last,
> validating each field as it runs.
> It all works fine except for the email address validation. This is OK
> if the field is empty or if the field is invalid - it either drops
> thru when empty, or issues an appropriate warning when the address is
> bad. The problem comes when the address is valid - the routine should
> drop thru to the next field validation, but doesn't! It just
> disappears into a black hole! All of the fields can still be altered
> and re-validated and if the email field is cleared or made invalid,
> the routine works again as expected.
>
> I guess I've probably got a brace misplaced, or misunderstood the
> rules for nesting.
>
> I do hope someone can point me in the right direction.

1. Get a text editor that highlights matching parentheses/brackets. For
Windows, I recommend UltraEdit, although there are others with this feature.

2. DO use a semicolon to terminate statements. Yes, I know they're not
usually required, but using them eliminates the possibility of hitting
one of those cases - and makes the code easier to read and debug.

3. DO use curly brackets for every if and else.

4. DON'T put if and else on the same line. (Sorry, David, I think this
is a *very* bad habit to encourage in people. JS has no
elseif/elif/etc., and we shouldn't pretend that it does.)

5. Anytime you've got this many if/else's, that's a signal that it's
time for you to look at a different construct, such as a for loop or
switch block. This also provides you the opportunity to separate your
code and data - this means: if your form changes, you change the array
(or other data structure), and not the code that actually does the work.
This makes it much easier to maintain.

function checkForm(form)
{
    //  each element of the array contains the field name
    //  and a display name
    var fields = [
                    ["Name", "name"],
                    ["House", "address"],
                    ["City", "town/city"],
                    ["County", "county"],
                    ["Email", "email"],
                    ["Age", "age"],
                    ["Plage", "playing age"],
                  ];

    var fieldName, field, displayName;
    var emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    var rValue = true;

    for(var i = 0; i < fields.length; i++)
    {
      fieldName = fields[i][0];
      field = form[fieldName];
      displayName = fields[i][1];

      if(field.value == "")
      {
        alert("The " + displayName + " is required.");
        rValue = false;
        field.focus();
        break;
      }
      else
      {
        if(fieldName == "Email" && !emlchk.test(field.value))
        {
          alert("Email address is invalid.");
          rValue = false;
          field.focus();
          field.select();
          break;
        }
      }
    }

    return rValue;
}

<input name="Print" type="button" value="Print form"
         onclick="if( checkForm(this.form) )window.print();">

If you use label attributes for your form fields, you can get rid of the
array, and simply pull everything you need from the form itself. This
would make your script much more portable.

DO NOT use global references for HTML elements in script - this works
only in MSIE. IOW, use document.AWSForm or document.forms["AWSForm"],
and not AWSForm, when referring to a form named "AWSForm".

The print() method takes no arguments, it's simply a method of the
window object. window.print() is all you need.

BTW, your regexp for the email check is out of date, as there are now
TLDs with more than 3 characters (e.g. .info).

cheers

jon.

>
> **********************************************************************
> *********************
>
> <script language="JavaScript">
>  <!-- Hide script from old browsers
>
>  emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})
> +$/            //for email address validation
>
> function empty (field,warning)
> {                                                //if mandatory field
> is empty, warn user
>  alert("You must fill in your "+warning+"!")
>  field.focus()
>  field.select()
>                                             }
>
> function printdoc(text)
> {                                                          //validate
> entire document field by field, then call printer
>  if (AWSform.Name.value == "") {
>   empty(AWSform.Name,"name")
>                                                }
>  else {
>   if (AWSform.House.value == "") {
>   empty(AWSform.House,"address")
>                                                  }
>    else {
>     if (AWSform.City.value == "") {
>     empty(AWSform.City,"town/city")
>                                                }
>     else {
>       if (AWSform.County.value == "") {
>       empty(AWSform.County,"county")
>                                                       }
>      else {
>         if (AWSform.Zip.value == "") {
>        empty(AWSform.Zip,"postcode")
>                                                   }
>       else {
>         if (AWSform.Email.value != "")
> {                                      //Houston we have a problem!!!
>   if (!emlchk.test(AWSform.Email.value))
> {                               //************************************
> **************
>       alert ("Invalid email
> address!")                                          //This works fine
> until the email check is true
>    AWSform.Email.focus
> ()                                                     //then it
> disappears into a 'black hole'
>    AWSform.Email.select
> ()                                                    //**************
> ************************************
>                                           }
>          }
>       else {
>           if (AWSform.Age.value == "") {
>           empty(AWSform.Age,"age")
>                                                      }
>        else {
>           if (AWSform.Plage.value == "") {
>           empty(AWSform.Plage,"playing age")
>                                                         }
>         else {
>   text=document
>   print(text)
>                }
>              }
>            }
>          }
>         }
>        }
>       }
>      }
>     }
>  // End hiding script from old browsers -->
> </script>
>
> HTML
>  <input name="Print" type="button" value="Print form"
> onclick="printdoc()">
>
> **********************************************************************
> *********************
>
> Regards,
>
> Alan.
> www.theatreorgans.co.uk
> Admin: 2nd Touch, SSusers and UKShopsmiths Groups
> Editor Adur & Sussex Federation NHW Web Pages
> Theatre Pipe Organ Builder
> ShopSmith V520
> Flatulus Antiquitus



--
This message has not been scanned for viruses.

Since I do not use a Microsoft operating
system or software, and use only plaintext
for email, there is little need for me to do so.

#14244 From: "David Smart" <smartware@...>
Date: Tue Sep 5, 2006 5:03 am
Subject: Re: [JavaScript] Re: My email evaluation
smartware_co...
Send Email Send Email
 
Jon

Not planning to get into a style war, but ...

if ()
  ...
else if ()
  ...
else
  ...

(with or without {} for the "then" parts and the final "else")

is absolutely normal and common for all C-type languages - C, C++, C#, Java,
JavaScript.  Also for Pascal and Pascal-type languages.

No, they don't have a formal elseif - they don't need it.  The only ones
that need it are those that use "end if", like Basic, Ada, etc.

E.g. http://www.csharp-station.com/Tutorials/Lesson03.aspx for a C# example.

And this from w3schools

<script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time<10)
{
document.write("<b>Good morning</b>")
}
else if (time>10 && time<16)
{
document.write("<b>Good day</b>")
}
else
{
document.write("<b>Hello World!</b>")
}
</script>http://www.w3schools.com/js/js_if_else.asp
Like it or not (I do like it) - it's here to stay.

Regards, Dave S

----- Original Message -----
From: "Jon Stephens" <jon@...>
To: <javascript_official@yahoogroups.com>
Sent: Tuesday, September 05, 2006 10:47 AM
Subject: [JavaScript] Re: My email evaluation


>
>> My email evaluation.
>>     Posted by: "Alan K Baker" alan@... wurlitzerwilly
>>     Date: Mon Sep 4, 2006 12:20 am (PDT)
>>
>> x-posted because no reply from other group.
>
> (??? Doesn't tell us anything - there are heaps of other mailing lists
> out there.)
>
>>
>> Hi all.
>>
>> I'm rather new to Javascript, although I've done a lot of programming
>> in past years, in other languages.
>>
>> Below is some code I have in development. I haven't included the
>> calling HTML which is a fairly simple form with Print, Clear and
>> Close buttons, except for the Print Button routine.
>>
>> It's a bit long winded with all the Else statements, but that's so it
>> starts with the first form field and ripples through to the last,
>> validating each field as it runs.
>> It all works fine except for the email address validation. This is OK
>> if the field is empty or if the field is invalid - it either drops
>> thru when empty, or issues an appropriate warning when the address is
>> bad. The problem comes when the address is valid - the routine should
>> drop thru to the next field validation, but doesn't! It just
>> disappears into a black hole! All of the fields can still be altered
>> and re-validated and if the email field is cleared or made invalid,
>> the routine works again as expected.
>>
>> I guess I've probably got a brace misplaced, or misunderstood the
>> rules for nesting.
>>
>> I do hope someone can point me in the right direction.
>
> 1. Get a text editor that highlights matching parentheses/brackets. For
> Windows, I recommend UltraEdit, although there are others with this
> feature.
>
> 2. DO use a semicolon to terminate statements. Yes, I know they're not
> usually required, but using them eliminates the possibility of hitting
> one of those cases - and makes the code easier to read and debug.
>
> 3. DO use curly brackets for every if and else.
>
> 4. DON'T put if and else on the same line. (Sorry, David, I think this
> is a *very* bad habit to encourage in people. JS has no
> elseif/elif/etc., and we shouldn't pretend that it does.)
>
> 5. Anytime you've got this many if/else's, that's a signal that it's
> time for you to look at a different construct, such as a for loop or
> switch block. This also provides you the opportunity to separate your
> code and data - this means: if your form changes, you change the array
> (or other data structure), and not the code that actually does the work.
> This makes it much easier to maintain.
>
> function checkForm(form)
> {
>   //  each element of the array contains the field name
>   //  and a display name
>   var fields = [
>                   ["Name", "name"],
>                   ["House", "address"],
>                   ["City", "town/city"],
>                   ["County", "county"],
>                   ["Email", "email"],
>                   ["Age", "age"],
>                   ["Plage", "playing age"],
>                 ];
>
>   var fieldName, field, displayName;
>   var emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
>   var rValue = true;
>
>   for(var i = 0; i < fields.length; i++)
>   {
>     fieldName = fields[i][0];
>     field = form[fieldName];
>     displayName = fields[i][1];
>
>     if(field.value == "")
>     {
>       alert("The " + displayName + " is required.");
>       rValue = false;
>       field.focus();
>       break;
>     }
>     else
>     {
>       if(fieldName == "Email" && !emlchk.test(field.value))
>       {
>         alert("Email address is invalid.");
>         rValue = false;
>         field.focus();
>         field.select();
>         break;
>       }
>     }
>   }
>
>   return rValue;
> }
>
> <input name="Print" type="button" value="Print form"
>        onclick="if( checkForm(this.form) )window.print();">
>
> If you use label attributes for your form fields, you can get rid of the
> array, and simply pull everything you need from the form itself. This
> would make your script much more portable.
>
> DO NOT use global references for HTML elements in script - this works
> only in MSIE. IOW, use document.AWSForm or document.forms["AWSForm"],
> and not AWSForm, when referring to a form named "AWSForm".
>
> The print() method takes no arguments, it's simply a method of the
> window object. window.print() is all you need.
>
> BTW, your regexp for the email check is out of date, as there are now
> TLDs with more than 3 characters (e.g. .info).
>
> cheers
>
> jon.
>
>>
>> **********************************************************************
>> *********************
>>
>> <script language="JavaScript">
>>  <!-- Hide script from old browsers
>>
>>  emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})
>> +$/            //for email address validation
>>
>> function empty (field,warning)
>> {                                                //if mandatory field
>> is empty, warn user
>>  alert("You must fill in your "+warning+"!")
>>  field.focus()
>>  field.select()
>>                                             }
>>
>> function printdoc(text)
>> {                                                          //validate
>> entire document field by field, then call printer
>>  if (AWSform.Name.value == "") {
>>   empty(AWSform.Name,"name")
>>                                                }
>>  else {
>>   if (AWSform.House.value == "") {
>>   empty(AWSform.House,"address")
>>                                                  }
>>    else {
>>     if (AWSform.City.value == "") {
>>     empty(AWSform.City,"town/city")
>>                                                }
>>     else {
>>       if (AWSform.County.value == "") {
>>       empty(AWSform.County,"county")
>>                                                       }
>>      else {
>>         if (AWSform.Zip.value == "") {
>>        empty(AWSform.Zip,"postcode")
>>                                                   }
>>       else {
>>         if (AWSform.Email.value != "")
>> {                                      //Houston we have a problem!!!
>>   if (!emlchk.test(AWSform.Email.value))
>> {                               //************************************
>> **************
>>       alert ("Invalid email
>> address!")                                          //This works fine
>> until the email check is true
>>    AWSform.Email.focus
>> ()                                                     //then it
>> disappears into a 'black hole'
>>    AWSform.Email.select
>> ()                                                    //**************
>> ************************************
>>                                           }
>>          }
>>       else {
>>           if (AWSform.Age.value == "") {
>>           empty(AWSform.Age,"age")
>>                                                      }
>>        else {
>>           if (AWSform.Plage.value == "") {
>>           empty(AWSform.Plage,"playing age")
>>                                                         }
>>         else {
>>   text=document
>>   print(text)
>>                }
>>              }
>>            }
>>          }
>>         }
>>        }
>>       }
>>      }
>>     }
>>  // End hiding script from old browsers -->
>> </script>
>>
>> HTML
>>  <input name="Print" type="button" value="Print form"
>> onclick="printdoc()">
>>
>> **********************************************************************
>> *********************
>>
>> Regards,
>>
>> Alan.
>> www.theatreorgans.co.uk
>> Admin: 2nd Touch, SSusers and UKShopsmiths Groups
>> Editor Adur & Sussex Federation NHW Web Pages
>> Theatre Pipe Organ Builder
>> ShopSmith V520
>> Flatulus Antiquitus
>
>
>
> --
> This message has not been scanned for viruses.
>
> Since I do not use a Microsoft operating
> system or software, and use only plaintext
> for email, there is little need for me to do so.
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
>
>
>
>
>
>
>

#14245 From: "Alan K Baker" <alan@...>
Date: Tue Sep 5, 2006 3:25 am
Subject: Re: [JavaScript] Re: My email evaluation
wurlitzerwilly
Send Email Send Email
 
Jon.

Thanks for your reply.

I only included the x-posted wording as a courtesy, not as a complaint, to save
myself from being complained at because I'd done it. :-)
As you ask, the "other group" is JS-Jive@yahoogroups.com. They've accepted my
membership, but my message hasn't yet appeared.

I use Macromedia's HomeSite as an editor because it seems to have a lot of
useful features and I like to be able to flip from coding to testing by the
press of f12.
It seems to catch most things, but often only in "run" mode, but it doesn't
always get it right. I left off "()" at the end of a line and just put the ";"
and HS told me it was expecting a ";" at line xx!
It also has the odd bug - in run mode, performing a "self.close()" will crash it
totally, but at least it exits politely! <g>
I'll definitely take a look at UltraEdit.

Point taken about the semicolons and curly brackets.

The jury's out on the if and else on one line - I don't want to offend anyone.
:-)

I do like the idea of the different construct and arrays and I'll look to
including them in further code. There are quite a few other aspects of
JavaScript that look interesting, that I want to get into.

As far as the regexp is concerned, I must admit that it was plagiarised and I
notice that the book has gone forward an edition or two!
In my defence, I was in a tearing hurry to get some code running for a friend,
and just grabbed what I saw. I do understand what it is trying to do, but I had
not checked it thoroughly for modernity. Oops! :-)
Also in my defence, I haven't written serious code such as JavaScript for over
ten years, so at 60 years of age, it takes a bit more time to get back into
"proper" methods, and one tends to skip some parts of books, because there's
pressure for quantity not quality! Also, prior to any high level language in the
past, I was most deeply embroiled in "bit manipulation" being employed to work
in assembly language, very processor specific, and RISC where straight line
coding was actually often faster than loops and branches!!!

Thanks also for the tip about "document.AWSform". That makes sense, I'll change
the code.

One last comment/question: Do you or David have a suggestion for elegantly
implementing an "or" method, such as "if ( x < y OR x > y ) { DO"   ?

Regards,

Alan.
www.theatreorgans.co.uk
Admin: 2nd Touch, SSusers and UKShopsmiths Groups
Editor Adur & Sussex Federation NHW Web Pages
Theatre Pipe Organ Builder
ShopSmith V520
Flatulus Antiquitus

   ----- Original Message -----
   From: Jon Stephens
   To: javascript_official@yahoogroups.com
   Sent: Tuesday, September 05, 2006 1:47 AM
   Subject: [JavaScript] Re: My email evaluation



   > My email evaluation.
   >     Posted by: "Alan K Baker" alan@... wurlitzerwilly
   >     Date: Mon Sep 4, 2006 12:20 am (PDT)
   >
   > x-posted because no reply from other group.

   (??? Doesn't tell us anything - there are heaps of other mailing lists
   out there.)

   1. Get a text editor that highlights matching parentheses/brackets. For
   Windows, I recommend UltraEdit, although there are others with this feature.

   2. DO use a semicolon to terminate statements. Yes, I know they're not
   usually required, but using them eliminates the possibility of hitting
   one of those cases - and makes the code easier to read and debug.

   3. DO use curly brackets for every if and else.

   4. DON'T put if and else on the same line. (Sorry, David, I think this
   is a *very* bad habit to encourage in people. JS has no
   elseif/elif/etc., and we shouldn't pretend that it does.)

   5. Anytime you've got this many if/else's, that's a signal that it's
   time for you to look at a different construct, such as a for loop or
   switch block. This also provides you the opportunity to separate your
   code and data - this means: if your form changes, you change the array
   (or other data structure), and not the code that actually does the work.
   This makes it much easier to maintain.

   function checkForm(form)
   {
      //  each element of the array contains the field name
      //  and a display name
      var fields = [
                      ["Name", "name"],
                      ["House", "address"],
                      ["City", "town/city"],
                      ["County", "county"],
                      ["Email", "email"],
                      ["Age", "age"],
                      ["Plage", "playing age"],
                    ];

      var fieldName, field, displayName;
      var emlchk = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
      var rValue = true;

      for(var i = 0; i < fields.length; i++)
      {
        fieldName = fields[i][0];
        field = form[fieldName];
        displayName = fields[i][1];

        if(field.value == "")
        {
          alert("The " + displayName + " is required.");
          rValue = false;
          field.focus();
          break;
        }
        else
        {
          if(fieldName == "Email" && !emlchk.test(field.value))
          {
            alert("Email address is invalid.");
            rValue = false;
            field.focus();
            field.select();
            break;
          }
        }
      }

      return rValue;
   }

   <input name="Print" type="button" value="Print form"
           onclick="if( checkForm(this.form) )window.print();">

   If you use label attributes for your form fields, you can get rid of the
   array, and simply pull everything you need from the form itself. This
   would make your script much more portable.

   DO NOT use global references for HTML elements in script - this works
   only in MSIE. IOW, use document.AWSForm or document.forms["AWSForm"],
   and not AWSForm, when referring to a form named "AWSForm".

   The print() method takes no arguments, it's simply a method of the
   window object. window.print() is all you need.

   BTW, your regexp for the email check is out of date, as there are now
   TLDs with more than 3 characters (e.g. .info).

   cheers

   jon.


[Non-text portions of this message have been removed]

#14246 From: "Alan K Baker" <alan@...>
Date: Tue Sep 5, 2006 9:03 am
Subject: Re: [JavaScript] Re: My email evaluation
wurlitzerwilly
Send Email Send Email
 
David.

Hmmm. That's a bit ironic, Internet Explorer 7 refuses to open that site! Oops.
:-)

Regards,

Alan.
www.theatreorgans.co.uk
Admin: 2nd Touch, SSusers and UKShopsmiths Groups
Editor Adur & Sussex Federation NHW Web Pages
Theatre Pipe Organ Builder
ShopSmith V520
Flatulus Antiquitus

   ----- Original Message -----
   From: David Smart
   To: JavaScript_Official@yahoogroups.com
   Sent: Tuesday, September 05, 2006 6:03 AM
   Subject: Re: [JavaScript] Re: My email evaluation



   E.g. http://www.csharp-station.com/Tutorials/Lesson03.aspx for a C# example.



[Non-text portions of this message have been removed]

#14247 From: "md_sagri" <md_sagri@...>
Date: Tue Sep 5, 2006 8:48 am
Subject: Solution to Ajax Prolem //Suggestion needed
md_sagri
Send Email Send Email
 
Hi all,
   I have been wondering days long to find a solution to, Ajax's error,


Error: [Exception... "Component returned failure code: 0x80040111
(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.statusText]"  nsresult:
"0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame ::
http://myhost:80/ajax/ajscripts.js :: processStateChange :: line 131"
  data: no]
Source File: http://myhost:80/ajax/ajscripts.js
Line: 131


   in my situation to print the result of a subscription (weather
subscription was successful or failed) in the left pane of my jsp page.
   I used my call to server in the following way in my jsp page.

  <input value="Subscribe" id="submit" type="submit" onclick =
"retrieveURL('SubscribeMail.do?name=subscriberReq','subscriberform');") >

  This transfer my request to ajax script where I am making the
asynchronous call to my server.

  var req;
function retrieveURL(url, nameOfFormToPost){
	  url=url+getFormAsString(nameOfFormToPost);
	  //Do the AJAX call
	  req = false;
   if (window.XMLHttpRequest) {
   try {
		 //Non-IE browsers
			 req = new XMLHttpRequest();
         } catch(e) {
		 //alert("in catch for non IE");
			 req = false;
         }
             // branch for IE/Windows ActiveX version
      }else if(window.ActiveXObject) {
       	 try {
        	 req = new ActiveXObject("Msxml2.XMLHTTP");
      	 } catch(e) {
        	 try {
          		 req = new ActiveXObject("Microsoft.XMLHTTP");
        	 } catch(e) {
          		 req = false;
        	 }
		 }
     }
	 if(req) {
		 //Set a function to be called after the response from the server is
returned.
		 req.onreadystatechange = processStateChange;
		 req.open("POST", url, true);//open the connection

		 setTimeout('processStateChange()',199);//ATTENTION

		 req.send(null); // make a call to the server

	 }
}// end of retrieveURL ?


      That is by setting a timeout to my processStateChange function
that will be processed after the XMLHttpRequest.status  becomes equal
to 200.

      function processStateChange(){
	  if (req.readyState == 4) {// Complete
	 // alert("check");
      var status = "";
   	 try{
     status = req.status;
   	 }catch(e){//alert(" exception ");
  	 status = "Trouble accessing it";
	 }
     if (status == "ok" || status == "OK" || status == 200) { //alert("
OK response reached now we can process the response");

        // alert("Ajax Response"+ req.responseText);
     //Function to split the text response into Span elements
     spanElements =
         splitTextIntoSpan(req.responseText);

     //Function to replace these span elements to update the jsp page");
     replaceExistingWithNewHtml(spanElements);

    }
     else {
       alert("Problem with browser response:\n Response status "
         + req.statusText);
     }
   }
}//processStateChange ends.


        With this approach, I am getting the desired output.
Ofcourse with a non-recomended way of delaying response at the client
end, by the use of set timeout().

        Once again, if you uncomment the alerts, you will notice that
the looping of setTimeout(processStateChange()',199) is not stoped as
soon as the status == 200
Rather it continues to call back the function for a quite larger no.
times, approximately 20.

        even though this process does not take more than seconds on my
system (local machine), when it is called by the use rit might be
problematic.

        Is this approach is acceptable or can any one give me the
issues of setTimeout. Any links that I can find in.

   Any suggestion welcome
  Thanks.

#14248 From: Greg Hope <g_hope@...>
Date: Tue Sep 5, 2006 8:25 pm
Subject: Working with time ranges
g_hope
Send Email Send Email
 
My googling is not leading me to the light. Here's my problem.

I need to change some page content (back and forth between A and B) based on
days of the week and time ranges for different days of the week. For example:

Monday through Thursday, 8:30am-4:30pm, include content A
Monday through Thursday, 4:30pm-8:30am, include content B
...et cetera

I've built a switch statement to handle the days and have embedded an if
statement in each case to test for the hours, but cannot figure out how to
handle the minutes since every minute of the clock is valid for some hours.

Does anyone have experience to share with time ranges?  I'm pasting in a snippet
of my code thus far, leaving off the repeating sections. Thanks for any
suggestions.  Greg

var dateobj=new Date()
var today=dateobj.getDay()
var hours=dateobj.getHours()
var minutes=dateobj.getMinutes()

switch(today) {
case 1:
document.write("not today")
break
case 2:
     if (hours > 8 && hours < 16) {
     document.write("content A")
     }
     else {
     document.write("content B")
     }
break
.
.
.


---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+
countries) for 2¢/min or less.

[Non-text portions of this message have been removed]

#14250 From: benjamin_m_hill
Date: Wed Sep 6, 2006 2:17 am
Subject: Assigning mouse actions to a table, post-rendering
benjamin_m_hill
 
So, I have printed out a table to the browser.  Is it possible to then
go back and assign actions to the TD cells of the table through a
JavaScript call?

Basically, something like this (but it doesn't work in Firefox)


function add_mice() {
   var cells = document.getElementsByTagName("td");
   for(var key in cells) {
    cells[key].onMouseDown=function(e){
      myMouseDown(e);
    }
   }
}

#14251 From: "Jonas Raoni" <jonasraoni@...>
Date: Wed Sep 6, 2006 3:58 am
Subject: Re: [JavaScript] Working with time ranges
jonasraoni
Send Email Send Email
 
On 9/5/06, Greg Hope <g_hope@...> wrote:
> Does anyone have experience to share with time ranges?  I'm pasting in a
> snippet of my code thus far, leaving off the repeating sections. Thanks for
any
> suggestions.  Greg

Bellow I just made an example of comparing the hours "in the hand",
but the easiest and shortest way is to make two Date objects and
compare them, if you want to just compare hours, this is a good way of
doing it:

var now = new Date, y = now.getFullYear(), m = now.getMonth(), d =
now.getDate(),
start = new Date(y, m, d, 12, 10), end = new Date(y, m, d, 13, 10);
alert(now >= start && now <= end ? "The current time is between 12:10
and 13:10" : "Wait, one day you'll see another message =bbbb");

Manual example xD

DayAlarm = function(){};
with({$: DayAlarm.prototype}){
	 $.items = {};
	 $.parse = function(time){
		 return {h: +(time = time.split(":"))[0], m: +time[1], s: +time[2]};
	 };
	 $.add = function(day, start, end, handler){
		 (this.items[day] || (this.items[day] = [])).push({
			 start: this.parse(start),
			 end: this.parse(end),
			 handler: handler
		 });
	 };
	 $.check = function(){
		 var d = new Date, w = d.getDay(), h = d.getHours(), m =
d.getMinutes(), secs = d.getSeconds();
		 for(var x, s, e, o, i = (o = this.items[w] || []).length; i--;
			 (s = o[i].start).h <= h && (e = o[i].end).h >= h
			 && (e.h == h ? (e.h == s.h ? s.m <= m : 1) && e.m >= m &&
			 (e.m == m ? (e.m == s.m ? s.s <= secs : 1) && e.s >= secs : 1) : 1) &&
			 (x = o[i].handler) instanceof Function && x(s, e, d)
		 );
	 };
}

var x = new DayAlarm;
x.add(0, "00:00:00", "23:59:59", function(){
	 alert("Be happy, it's sunday xDDD");
});

function monday(){
	 alert("Be sad, monday again... Go work :D");
}

x.add(1, "00:45:15", "00:45:59", monday);

x.check();


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

#14252 From: "RPGIV Programmer" <rpgivprogrammer@...>
Date: Wed Sep 6, 2006 5:31 am
Subject: RE: [JavaScript] Working with time ranges
rpgivprogram...
Send Email Send Email
 
Convert your time to minutes past midnight. If time is PM add 12 to the
hours.
multiply hours by 60 and add the minutes.
You can put this into one clean little function.






Sincerely;

My Web Page <http://home.earthlink.net/~carlpheneger>




-----Original Message-----
From: JavaScript_Official@yahoogroups.com
[mailto:JavaScript_Official@yahoogroups.com] On Behalf Of Greg Hope
Sent: Tuesday, September 05, 2006 3:26 PM
To: JavaScript Group
Subject: [JavaScript] Working with time ranges



My googling is not leading me to the light. Here's my problem.

I need to change some page content (back and forth between A and B) based on
days of the week and time ranges for different days of the week. For
example:

Monday through Thursday, 8:30am-4:30pm, include content A
Monday through Thursday, 4:30pm-8:30am, include content B
...et cetera

I've built a switch statement to handle the days and have embedded an if
statement in each case to test for the hours, but cannot figure out how to
handle the minutes since every minute of the clock is valid for some hours.



---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+
countries) for 2¢/min or less.

[Non-text portions of this message have been removed]





[Non-text portions of this message have been removed]

#14253 From: Greg Hope <g_hope@...>
Date: Wed Sep 6, 2006 7:20 am
Subject: Re: [JavaScript] Working with time ranges
g_hope
Send Email Send Email
 
Wow! I'm going to have to read this twice to understand it. Thanks very much,
Jonas. May you please explain the $ notation that appears in several places?
This is something I have not seen before.

Greg

Jonas Raoni <jonasraoni@...> wrote:                                  On
9/5/06, Greg Hope <g_hope@...> wrote:
  > Does anyone have experience to share with time ranges?  I'm pasting in a
  > snippet of my code thus far, leaving off the repeating sections. Thanks for
any
  > suggestions.  Greg

  Bellow I just made an example of comparing the hours "in the hand",
  but the easiest and shortest way is to make two Date objects and
  compare them, if you want to just compare hours, this is a good way of
  doing it:

  var now = new Date, y = now.getFullYear(), m = now.getMonth(), d =
  now.getDate(),
  start = new Date(y, m, d, 12, 10), end = new Date(y, m, d, 13, 10);
  alert(now >= start && now <= end ? "The current time is between 12:10
  and 13:10" : "Wait, one day you'll see another message =bbbb");

  Manual example xD

  DayAlarm = function(){};
  with({$: DayAlarm.prototype}){
   $.items = {};
   $.parse = function(time){
    return {h: +(time = time.split(":"))[0], m: +time[1], s: +time[2]};
   };
   $.add = function(day, start, end, handler){
    (this.items[day] || (this.items[day] = [])).push({
     start: this.parse(start),
     end: this.parse(end),
     handler: handler
    });
   };
   $.check = function(){
    var d = new Date, w = d.getDay(), h = d.getHours(), m =
  d.getMinutes(), secs = d.getSeconds();
    for(var x, s, e, o, i = (o = this.items[w] || []).length; i--;
     (s = o[i].start).h <= h && (e = o[i].end).h >= h
     && (e.h == h ? (e.h == s.h ? s.m <= m : 1) && e.m >= m &&
     (e.m == m ? (e.m == s.m ? s.s <= secs : 1) && e.s >= secs : 1) : 1) &&
     (x = o[i].handler) instanceof Function && x(s, e, d)
    );
   };
  }

  var x = new DayAlarm;
  x.add(0, "00:00:00", "23:59:59", function(){
   alert("Be happy, it's sunday xDDD");
  });

  function monday(){
   alert("Be sad, monday again... Go work :D");
  }

  x.add(1, "00:45:15", "00:45:59", monday);

  x.check();

  --
  Jonas Raoni Soares Silva
  http://www.jsfromhell.com






---------------------------------
Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small
Business.

[Non-text portions of this message have been removed]

#14254 From: "David Smart" <smartware@...>
Date: Wed Sep 6, 2006 9:46 am
Subject: Re: [JavaScript] Re: My email evaluation
smartware_co...
Send Email Send Email
 
Interesting indeed.  I'm using IE6 and it works fine there.

Regards, Dave S

----- Original Message -----
From: "Alan K Baker" <alan@...>
To: <JavaScript_Official@yahoogroups.com>
Sent: Tuesday, September 05, 2006 7:03 PM
Subject: Re: [JavaScript] Re: My email evaluation


> David.
>
> Hmmm. That's a bit ironic, Internet Explorer 7 refuses to open that site!
> Oops. :-)
>
> Regards,
>
> Alan.
> www.theatreorgans.co.uk
> Admin: 2nd Touch, SSusers and UKShopsmiths Groups
> Editor Adur & Sussex Federation NHW Web Pages
> Theatre Pipe Organ Builder
> ShopSmith V520
> Flatulus Antiquitus
>
>  ----- Original Message -----
>  From: David Smart
>  To: JavaScript_Official@yahoogroups.com
>  Sent: Tuesday, September 05, 2006 6:03 AM
>  Subject: Re: [JavaScript] Re: My email evaluation
>
>
>
>  E.g. http://www.csharp-station.com/Tutorials/Lesson03.aspx for a C#
> example.
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

#14255 From: "David Smart" <smartware@...>
Date: Wed Sep 6, 2006 10:40 am
Subject: Re: [JavaScript] Assigning mouse actions to a table, post-rendering
smartware_co...
Send Email Send Email
 
Not doing any testing on this, but off the top of my head ...

>  for(var key in cells) {
>   cells[key].onMouseDown=function(e){  ...

I would expect that key would be an actual cell reference, not an index into
the cells collection.  I.e.

   key.onMouseDown=function(e){  ...

[again, I stress - just a thought, not tested or researched]


Regards, Dave S

----- Original Message -----
From: "benjamin_m_hill" <no_reply@yahoogroups.com>
To: <JavaScript_Official@yahoogroups.com>
Sent: Wednesday, September 06, 2006 12:17 PM
Subject: [JavaScript] Assigning mouse actions to a table, post-rendering


> So, I have printed out a table to the browser.  Is it possible to then
> go back and assign actions to the TD cells of the table through a
> JavaScript call?
>
> Basically, something like this (but it doesn't work in Firefox)
>
>
> function add_mice() {
>  var cells = document.getElementsByTagName("td");
>  for(var key in cells) {
>   cells[key].onMouseDown=function(e){
>     myMouseDown(e);
>   }
>  }
> }
>
>
>
>
>
>
>
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

#14256 From: "Alan K Baker" <alan@...>
Date: Wed Sep 6, 2006 11:03 am
Subject: Re: [JavaScript] Re: My email evaluation
wurlitzerwilly
Send Email Send Email
 
Hi David.

IE7 is in Beta 2 ! :-)

Regards,

Alan.
www.theatreorgans.co.uk
Admin: 2nd Touch, SSusers and UKShopsmiths Groups
Editor Adur & Sussex Federation NHW Web Pages
Theatre Pipe Organ Builder
ShopSmith V520
Flatulus Antiquitus

   ----- Original Message -----
   From: David Smart
   To: JavaScript_Official@yahoogroups.com
   Sent: Wednesday, September 06, 2006 10:46 AM
   Subject: Re: [JavaScript] Re: My email evaluation


   Interesting indeed.  I'm using IE6 and it works fine there.

   Regards, Dave S


[Non-text portions of this message have been removed]

#14257 From: willfreer04
Date: Wed Sep 6, 2006 1:45 pm
Subject: Swf into Acrobat
willfreer04
 
I noticed that Swf doesn't play in Acrobat 7. but it plays fine in 6.
Is there some code missing in the Acrobat 7, that I need to add? Or a
code in the Flash to make it work in Acrobat 7?

Thanks

#14258 From: "Jonas Raoni" <jonasraoni@...>
Date: Wed Sep 6, 2006 1:39 pm
Subject: Re: [JavaScript] Working with time ranges
jonasraoni
Send Email Send Email
 
On 9/6/06, Greg Hope <g_hope@...> wrote:
> Wow! I'm going to have to read this twice to understand it. Thanks very much,

lol, the only usefull part for you is the first script and this part
of the other one:

s is the start time and e is the end time =b

s.h <= h && e.h >= h
&& (e.h == h ? (e.h == s.h ? s.m <= m : 1) && e.m >= m
&& (e.m == m ? (e.m == s.m ? s.s <= secs : 1) && e.s >= secs : 1) : 1)

If all these conditions are true, the current hour is between the
limits (I didn't checked if the "end" is higher than the "start", so
if you use "wrong" values it may fail)

> Jonas. May you please explain the $ notation that appears in several places?
This
> is something I have not seen before.

In many languages people think they are allowed only to use simple a-z
plus the underscore character when naming variables, but you can name
them using other characters too :D

Test this:

var joćo = 123;
alert(joćo);

But since you may not have some characters that I have on my keyboard,
it's better to avoid using such things :D


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

#14259 From: liorean <liorean@...>
Date: Wed Sep 6, 2006 11:20 am
Subject: Re: [JavaScript] Assigning mouse actions to a table, post-rendering
liorean
Send Email Send Email
 
On 06/09/06, benjamin_m_hill <no_reply@yahoogroups.com> wrote:
> Basically, something like this (but it doesn't work in Firefox)

Of course it doesn't work. The for..in loop loops over properties of
an object, not over items in a collection. Do it like this instead:

     var
         elm;
         i=0,
         coll=document.getElementsByTagName('td');
     while(elm=coll.item(i++))
         elm.onmousedown=function(e){
             myMouseDown(e);
         };
--
David "liorean" Andersson
<uri:http://liorean.web-graphics.com/>

#14260 From: "Eugene Donaghy" <eugene.donaghy@...>
Date: Wed Sep 6, 2006 7:42 pm
Subject: cookies for dummies
eugene_donaghy
Send Email Send Email
 
HI there

How do i set a cookie in javascript ??

Eugene

#14261 From: "David Smart" <smartware@...>
Date: Wed Sep 6, 2006 9:22 pm
Subject: Re: [JavaScript] cookies for dummies
smartware_co...
Send Email Send Email
 
Have you tried Google at all?

Regards, Dave S

----- Original Message -----
From: "Eugene Donaghy" <eugene.donaghy@...>
To: <JavaScript_Official@yahoogroups.com>
Sent: Thursday, September 07, 2006 5:42 AM
Subject: [JavaScript] cookies for dummies


> HI there
>
> How do i set a cookie in javascript ??
>
> Eugene
>
>
>
>
>
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
>
>
>
>
>
>

Messages 14231 - 14261 of 16942   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help