switch or select case and code inside it

Discussion in 'Javascript' started by richard, Nov 4, 2008.

  1. richard

    richard Guest

    I've been tossing around the idea now that maybe my problem might be
    better resolved by using the "select case"/switch command.

    The only problem is, all the dozens of sites I've seen so far only
    give very brief examples using the very basic things.
    Such as:

    select case name
    case "adam"
    document.write("adam")

    or what ever.

    They might mention that is possible to put code into this statement
    but show no examples of this.
    Let alone show how to pass a value to the "case" other than by manual
    input in the coding.

    Assume I have 3 links.
    Link 1.
    Link 2.
    Link 3.

    The opening and default is link 1.
    User clicks on link 2, what's ever showing in that visible <div 1> is
    replaced with <div 2>.

    How would I best do this?
     
    richard, Nov 4, 2008
    #1
    1. Advertising

  2. richard

    David Mark Guest

    On Nov 3, 11:26 pm, richard <> wrote:
    > I've been tossing around the idea now that maybe my problem might be
    > better resolved by using the "select case"/switch command.
    >


    A switch statement?

    https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/switch

    > The only problem is, all the dozens of sites I've seen so far only
    > give very brief examples using the very basic things.


    Dozens huh? That must have been frustrating.

    > Such as:
    >
    > select case name
    > case "adam"
    > document.write("adam")
    >
    > or what ever.


    Such as what?

    >
    > They might mention that is possible to put code into this statement
    > but show no examples of this.


    How dare they?

    > Let alone show how to pass a value to the "case" other than by manual
    > input in the coding.


    Other than by what?

    >
    > Assume I have 3 links.


    Okay.

    > Link 1.
    > Link 2.
    > Link 3.


    Yes, I see them.

    >
    > The opening and default is link 1.


    What makes it the default? It looks like the other two to me. None
    really look like links at all (not proper links.)

    > User clicks on link 2, what's ever showing in that visible <div 1> is
    > replaced with <div 2>.


    I must have missed divs 1 & 2.

    >
    > How would I best do this?


    Start by explaining what you are trying to do.
     
    David Mark, Nov 4, 2008
    #2
    1. Advertising

  3. richard

    richard Guest

    On Mon, 3 Nov 2008 20:44:57 -0800 (PST), David Mark
    <> wrote:

    >On Nov 3, 11:26 pm, richard <> wrote:
    >> I've been tossing around the idea now that maybe my problem might be
    >> better resolved by using the "select case"/switch command.
    >>

    >
    >A switch statement?
    >
    >https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/switch
    >
    >> The only problem is, all the dozens of sites I've seen so far only
    >> give very brief examples using the very basic things.

    >
    >Dozens huh? That must have been frustrating.
    >
    >> Such as:
    >>
    >> select case name
    >> case "adam"
    >> document.write("adam")
    >>
    >> or what ever.

    >
    >Such as what?
    >
    >>
    >> They might mention that is possible to put code into this statement
    >> but show no examples of this.

    >
    >How dare they?
    >
    >> Let alone show how to pass a value to the "case" other than by manual
    >> input in the coding.

    >
    >Other than by what?
    >
    >>
    >> Assume I have 3 links.

    >
    >Okay.
    >
    >> Link 1.
    >> Link 2.
    >> Link 3.

    >
    >Yes, I see them.
    >
    >>
    >> The opening and default is link 1.

    >
    >What makes it the default? It looks like the other two to me. None
    >really look like links at all (not proper links.)
    >
    >> User clicks on link 2, what's ever showing in that visible <div 1> is
    >> replaced with <div 2>.

    >
    >I must have missed divs 1 & 2.
    >
    >>
    >> How would I best do this?

    >
    >Start by explaining what you are trying to do.



    I just did.

    Still, your example does not show how one passes the value to the
    {expression}.

    <a href="www.google.com">Link 1</a>

    from your example
    switch (expr) {
    case "Oranges":
    document.write("Oranges are $0.59 a pound.<br>");
    break;

    }


    how do you get "Oranges" applied to the value in (expr)?

    Now can you answer that without the crapola?
     
    richard, Nov 4, 2008
    #3
  4. richard

    David Mark Guest

    On Nov 4, 12:07 am, richard <> wrote:
    > On Mon, 3 Nov 2008 20:44:57 -0800 (PST), David Mark
    >
    >
    >
    > <> wrote:
    > >On Nov 3, 11:26 pm, richard <> wrote:
    > >> I've been tossing around the idea now that maybe my problem might be
    > >> better resolved by using the "select case"/switch command.

    >
    > >A switch statement?

    >
    > >https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statem...

    >
    > >> The only problem is, all the dozens of sites I've seen so far only
    > >> give very brief examples using the very basic things.

    >
    > >Dozens huh?  That must have been frustrating.

    >
    > >> Such as:

    >
    > >> select case name
    > >> case "adam"
    > >> document.write("adam")

    >
    > >> or what ever.

    >
    > >Such as what?

    >
    > >> They might mention that is possible to put code into this statement
    > >> but show no examples of this.

    >
    > >How dare they?

    >
    > >> Let alone show how to pass a value to the "case" other than by manual
    > >> input in the coding.

    >
    > >Other than by what?

    >
    > >> Assume I have 3 links.

    >
    > >Okay.

    >
    > >> Link 1.
    > >> Link 2.
    > >> Link 3.

    >
    > >Yes, I see them.

    >
    > >> The opening and default is link 1.

    >
    > >What makes it the default?  It looks like the other two to me.  None
    > >really look like links at all (not proper links.)

    >
    > >> User clicks on link 2, what's ever showing in that visible <div 1> is
    > >> replaced with <div 2>.

    >
    > >I must have missed divs 1 & 2.

    >
    > >> How would I best do this?

    >
    > >Start by explaining what you are trying to do.

    >
    > I just did.


    Coherently.

    >
    > Still, your example does not show how one passes the value to the
    > {expression}.


    What example is that?

    >
    > <a href="www.google.com">Link 1</a>
    >
    > from your example


    My example?

    > switch (expr) {
    >    case "Oranges":
    >       document.write("Oranges are $0.59 a pound.<br>");
    >       break;
    >
    > }


    I've never seen that.

    >
    > how do you get "Oranges" applied to the value in (expr)?


    expr = "Oranges";

    >
    > Now can you answer that without the crapola?


    Perhaps you should file a complaint.
     
    David Mark, Nov 4, 2008
    #4
  5. richard

    richard Guest

    On Mon, 3 Nov 2008 21:16:38 -0800 (PST), David Mark
    <> wrote:

    >On Nov 4, 12:07 am, richard <> wrote:
    >> On Mon, 3 Nov 2008 20:44:57 -0800 (PST), David Mark
    >>
    >>
    >>
    >> <> wrote:
    >> >On Nov 3, 11:26 pm, richard <> wrote:
    >> >> I've been tossing around the idea now that maybe my problem might be
    >> >> better resolved by using the "select case"/switch command.

    >>
    >> >A switch statement?

    >>
    >> >https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statem...

    >>
    >> >> The only problem is, all the dozens of sites I've seen so far only
    >> >> give very brief examples using the very basic things.

    >>
    >> >Dozens huh?  That must have been frustrating.

    >>
    >> >> Such as:

    >>
    >> >> select case name
    >> >> case "adam"
    >> >> document.write("adam")

    >>
    >> >> or what ever.

    >>
    >> >Such as what?

    >>
    >> >> They might mention that is possible to put code into this statement
    >> >> but show no examples of this.

    >>
    >> >How dare they?

    >>
    >> >> Let alone show how to pass a value to the "case" other than by manual
    >> >> input in the coding.

    >>
    >> >Other than by what?

    >>
    >> >> Assume I have 3 links.

    >>
    >> >Okay.

    >>
    >> >> Link 1.
    >> >> Link 2.
    >> >> Link 3.

    >>
    >> >Yes, I see them.

    >>
    >> >> The opening and default is link 1.

    >>
    >> >What makes it the default?  It looks like the other two to me.  None
    >> >really look like links at all (not proper links.)

    >>
    >> >> User clicks on link 2, what's ever showing in that visible <div 1> is
    >> >> replaced with <div 2>.

    >>
    >> >I must have missed divs 1 & 2.

    >>
    >> >> How would I best do this?

    >>
    >> >Start by explaining what you are trying to do.

    >>
    >> I just did.

    >
    >Coherently.
    >
    >>
    >> Still, your example does not show how one passes the value to the
    >> {expression}.

    >
    >What example is that?
    >
    >>
    >> <a href="www.google.com">Link 1</a>
    >>
    >> from your example

    >
    >My example?
    >
    >> switch (expr) {
    >>    case "Oranges":
    >>       document.write("Oranges are $0.59 a pound.<br>");
    >>       break;
    >>
    >> }

    >
    >I've never seen that.
    >
    >>
    >> how do you get "Oranges" applied to the value in (expr)?

    >
    >expr = "Oranges";


    No shit sherlock.
    Exactly how is this accomplished in the actual coding?


    >
    >>
    >> Now can you answer that without the crapola?

    >
    >Perhaps you should file a complaint.
     
    richard, Nov 4, 2008
    #5
  6. richard

    David Mark Guest

    On Nov 4, 12:26 am, richard <> wrote:
    > On Mon, 3 Nov 2008 21:16:38 -0800 (PST), David Mark
    >
    >
    >
    > <> wrote:
    > >On Nov 4, 12:07 am, richard <> wrote:
    > >> On Mon, 3 Nov 2008 20:44:57 -0800 (PST), David Mark

    >
    > >> <> wrote:
    > >> >On Nov 3, 11:26 pm, richard <> wrote:
    > >> >> I've been tossing around the idea now that maybe my problem might be
    > >> >> better resolved by using the "select case"/switch command.

    >
    > >> >A switch statement?

    >
    > >> >https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statem....

    >
    > >> >> The only problem is, all the dozens of sites I've seen so far only
    > >> >> give very brief examples using the very basic things.

    >
    > >> >Dozens huh?  That must have been frustrating.

    >
    > >> >> Such as:

    >
    > >> >> select case name
    > >> >> case "adam"
    > >> >> document.write("adam")

    >
    > >> >> or what ever.

    >
    > >> >Such as what?

    >
    > >> >> They might mention that is possible to put code into this statement
    > >> >> but show no examples of this.

    >
    > >> >How dare they?

    >
    > >> >> Let alone show how to pass a value to the "case" other than by manual
    > >> >> input in the coding.

    >
    > >> >Other than by what?

    >
    > >> >> Assume I have 3 links.

    >
    > >> >Okay.

    >
    > >> >> Link 1.
    > >> >> Link 2.
    > >> >> Link 3.

    >
    > >> >Yes, I see them.

    >
    > >> >> The opening and default is link 1.

    >
    > >> >What makes it the default?  It looks like the other two to me.  None
    > >> >really look like links at all (not proper links.)

    >
    > >> >> User clicks on link 2, what's ever showing in that visible <div 1> is
    > >> >> replaced with <div 2>.

    >
    > >> >I must have missed divs 1 & 2.

    >
    > >> >> How would I best do this?

    >
    > >> >Start by explaining what you are trying to do.

    >
    > >> I just did.

    >
    > >Coherently.

    >
    > >> Still, your example does not show how one passes the value to the
    > >> {expression}.

    >
    > >What example is that?

    >
    > >> <a href="www.google.com">Link 1</a>

    >
    > >> from your example

    >
    > >My example?

    >
    > >> switch (expr) {
    > >>    case "Oranges":
    > >>       document.write("Oranges are $0.59 a pound.<br>");
    > >>       break;

    >
    > >> }

    >
    > >I've never seen that.

    >
    > >> how do you get "Oranges" applied to the value in (expr)?

    >
    > >expr = "Oranges";

    >
    > No shit sherlock.


    Well, you asked.

    > Exactly how is this accomplished in the actual coding?


    The actual coding of what?
     
    David Mark, Nov 4, 2008
    #6
  7. richard

    richard Guest

    On Mon, 03 Nov 2008 20:26:11 -0800, richard <>
    wrote:

    >I've been tossing around the idea now that maybe my problem might be
    >better resolved by using the "select case"/switch command.
    >
    >The only problem is, all the dozens of sites I've seen so far only
    >give very brief examples using the very basic things.
    >Such as:
    >
    >select case name
    >case "adam"
    >document.write("adam")
    >
    >or what ever.
    >
    >They might mention that is possible to put code into this statement
    >but show no examples of this.
    >Let alone show how to pass a value to the "case" other than by manual
    >input in the coding.
    >
    >Assume I have 3 links.
    >Link 1.
    >Link 2.
    >Link 3.
    >
    >The opening and default is link 1.
    >User clicks on link 2, what's ever showing in that visible <div 1> is
    >replaced with <div 2>.
    >
    >How would I best do this?
    >
    >
    >
    >
    >


    Think I've got this figured out now.
     
    richard, Nov 4, 2008
    #7
  8. richard meinte:

    [snip]
    > Think I've got this figured out now.


    Ooooh, too bad - you were quite entertaining.
     
    Gregor Kofler, Nov 6, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tee
    Replies:
    3
    Views:
    7,907
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. , India
    Replies:
    14
    Views:
    674
    James Kanze
    Jun 18, 2007
  3. aa
    Replies:
    14
    Views:
    341
  4. Robert Scheer

    Switch as a Select Case

    Robert Scheer, Jan 6, 2004, in forum: Javascript
    Replies:
    19
    Views:
    204
    Thomas 'PointedEars' Lahn
    Jan 20, 2004
  5. Replies:
    31
    Views:
    261
    Tim Rentsch
    Apr 15, 2014
Loading...

Share This Page