[Javascript] select-case construct (amended)

Mark Christie MChristie at avsgroup.com
Mon Oct 29 15:23:53 CST 2001


Yes.  :^)

Either add an ending } before the else clause:

switch(selStatus){
               case "Image from Design":
                    if(document.forms[0].toDesign.value==""){
                         document.forms[0].toDesign.value=todayDate;
                    } else {
document.forms[0].toDesign.value=document.forms[0].toDesign.value + "," +
todayDate;
                    }
                    break master
                    }

 or get rid of the beginning { after the if condition:

switch(selStatus){
               case "Image from Design":
                    if(document.forms[0].toDesign.value=="")
                         document.forms[0].toDesign.value=todayDate;
                    else {
document.forms[0].toDesign.value=document.forms[0].toDesign.value + "," +
todayDate;
                    }
                    break master
                    }

Regards,
   -Mark C.


-----Original Message-----
From: Esther_Strom at hmco.com [mailto:Esther_Strom at hmco.com]
Sent: Monday, October 29, 2001 2:51 PM
To: javascript at LaTech.edu
Subject: RE: [Javascript] select-case construct (amended)



Thanks to both of you for your help. Now another question: is there any
reason I can't use an if/else inside a case?


This works:

switch(selStatus){
               case "Image from Design":
                    if(document.forms[0].toDesign.value==""){
                         document.forms[0].toDesign.value=todayDate;
                    break master
                    }


This doesn't:

switch(selStatus){
               case "Image from Design":
                    if(document.forms[0].toDesign.value==""){
                         document.forms[0].toDesign.value=todayDate;
                    else {
document.forms[0].toDesign.value=document.forms[0].toDesign.value + "," +
todayDate;
                    }
                    break master
                    }

It's fine until I add the "else"; then it causes a syntax error. Am I
missing something really obvious here?

Thanks,

Esther


 

                    "Filipiak, Bob

                    (Contractor)"            To:
"'javascript at LaTech.edu'" <javascript at LaTech.edu>                 
                    <filipiab at atsc.ar        cc:

                    my.mil>                  Subject:     RE: [Javascript]
select-case construct (amended)             
                    Sent by:

                    javascript-admin@

                    LaTech.edu

 

 

                    10/29/01 02:11 PM

                    Please respond to

                    javascript

 

 





switch expr {
   CASE label:
   ....
}


should work for NS 4.x and above according to my "Pure JavaScript."





Bob Filipiak
(Contractor)













-----Original Message-----
From: Esther_Strom at hmco.com [mailto:Esther_Strom at hmco.com]
Sent: Monday, October 29, 2001 3:00 PM
To: javascript at LaTech.edu
Subject: [Javascript] select-case construct (amended)





Forgot to mention...this needs to work in NS4.7 for PC and Mac.


Thanks.
----- Forwarded by Esther Strom/McDougal/hmco on 10/29/01 01:58 PM -----

                    Esther Strom

                                         To:     javascript at LaTech.edu

                    10/29/01             cc:

                    01:58 PM             Subject:     select-case construct








I'm sure this has been mentioned before, but I can't find the message or an

example in any of my books. Can you use a select-case construct in
javascript?


Pseudocode example:


select case prodStatus


Case "New"
//do this


Case "In Progress"
//do this


Case else
//do this


End select


Thanks for any help available.


Esther





_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript







_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list