switch or select case and code inside it

R

richard

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?
 
D

David Mark

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.
 
R

richard

A switch statement?

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


Dozens huh? That must have been frustrating.


Such as what?


How dare they?


Other than by what?


Yes, I see them.


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


I must have missed divs 1 & 2.


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?
 
D

David Mark

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.
 
R

richard

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top