Switch/case how to use it correctly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard

    #1

    Switch/case how to use it correctly

    I've been looking at implementing switch/case on my photo gallery.
    Most of the sites I've seen so far, only show the bare basics.
    With no real practical examples.
    As brucie does with his butterlies and bugs, he uses switch/case, but in
    php.

    Visitor clicks on a thumbnail selection and the thumbs appear.
    Selection of a thumb shows the larger pic AND description.

    Since the selection is basically making a choice as within a form, how does
    one go about applying what has been chosen, to appear in the proper place?
    In the examples, they all favor using simple alert messages as examples.

    What I need, is an example of how to manipulate the cases and direct the
    coding to the proper areas.

    If anyone has a site that would explain this better, please post it.



  • Michael Winter

    #2
    Re: Switch/case how to use it correctly

    On Sat, 29 Jan 2005 09:45:17 -0600, Richard <Anonymous@127. 001> wrote:
    [color=blue]
    > I've been looking at implementing switch/case on my photo gallery.[/color]

    Why? Do you really want to write a case clause for every single image in
    the gallery?

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    • Richard

      #3
      Re: Switch/case how to use it correctly

      On Sat, 29 Jan 2005 16:27:54 GMT Michael Winter wrote:
      [color=blue]
      > On Sat, 29 Jan 2005 09:45:17 -0600, Richard <Anonymous@127. 001> wrote:[/color]
      [color=blue][color=green]
      >> I've been looking at implementing switch/case on my photo gallery.[/color][/color]
      [color=blue]
      > Why? Do you really want to write a case clause for every single image
      > in
      > the gallery?[/color]
      [color=blue]
      > [snip][/color]

      Would it not be easier than writing a swap routine for each and every image?
      As I see it, that's the purpose of switch/case.
      A simpler way of writing if/then.
      I would much rather write onclick="dothis ()" then
      onclick="docume nt.image.src="b lah blah" for each and every item.


      Comment

      • Mick White

        #4
        Re: Switch/case how to use it correctly

        Richard wrote:
        [color=blue]
        > I've been looking at implementing switch/case on my photo gallery.
        > Most of the sites I've seen so far, only show the bare basics.
        > With no real practical examples.
        > As brucie does with his butterlies and bugs, he uses switch/case, but in
        > php.
        >[/color]


        The "switch/case" construct is the method of last resort, imho.
        Mick

        [color=blue]
        > Visitor clicks on a thumbnail selection and the thumbs appear.
        > Selection of a thumb shows the larger pic AND description.
        >
        > Since the selection is basically making a choice as within a form, how does
        > one go about applying what has been chosen, to appear in the proper place?
        > In the examples, they all favor using simple alert messages as examples.
        >
        > What I need, is an example of how to manipulate the cases and direct the
        > coding to the proper areas.
        >
        > If anyone has a site that would explain this better, please post it.
        >
        >
        >[/color]

        Comment

        • Michael Winter

          #5
          Re: Switch/case how to use it correctly

          On Sat, 29 Jan 2005 10:48:08 -0600, Richard <Anonymous@127. 001> wrote:
          [color=blue]
          > On Sat, 29 Jan 2005 16:27:54 GMT Michael Winter wrote:[/color]

          [snip]
          [color=blue][color=green]
          >> Do you really want to write a case clause for every single image in the
          >> gallery?[/color]
          >[color=green]
          >> [snip][/color]
          >
          > Would it not be easier than writing a swap routine for each and every
          > image?[/color]

          What on Earth gives you the impression that that's necessary? Good grief!
          [color=blue]
          > As I see it, that's the purpose of switch/case.
          > A simpler way of writing if/then.[/color]

          The purpose of the switch statement is to compare many values to a single
          expression. In general, if statements evaluate different expressions.
          [color=blue]
          > I would much rather write onclick="dothis ()" then
          > onclick="docume nt.image.src="b lah blah" for each and every item.[/color]

          Both are excessive.

          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          • Randy Webb

            #6
            Re: Switch/case how to use it correctly

            Richard wrote:[color=blue]
            > On Sat, 29 Jan 2005 16:27:54 GMT Michael Winter wrote:
            >
            >[color=green]
            >>On Sat, 29 Jan 2005 09:45:17 -0600, Richard <Anonymous@127. 001> wrote:[/color]
            >
            >[color=green][color=darkred]
            >>>I've been looking at implementing switch/case on my photo gallery.[/color][/color]
            >
            >[color=green]
            >>Why? Do you really want to write a case clause for every single image
            >>in
            >>the gallery?[/color]
            >
            >[color=green]
            >>[snip][/color]
            >
            >
            > Would it not be easier than writing a swap routine for each and every image?[/color]

            No. The easiest way would be a function that accepts generic parameters
            and acts upon those parameters. Of course, to write such a function
            requires at least a minimum understanding of scripting.
            [color=blue]
            > As I see it, that's the purpose of switch/case.[/color]

            No, the above mentioned use is not the purpose of switch/case
            [color=blue]
            > A simpler way of writing if/then.[/color]

            Yes.
            [color=blue]
            > I would much rather write onclick="dothis ()" then
            > onclick="docume nt.image.src="b lah blah" for each and every item.[/color]

            onclick="doThis ('imageName','d iv Text');return false"

            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq

            Comment

            • Richard

              #7
              Re: Switch/case how to use it correctly

              On Sat, 29 Jan 2005 18:09:53 GMT Mick White wrote:
              [color=blue]
              > Richard wrote:[/color]
              [color=blue][color=green]
              >> I've been looking at implementing switch/case on my photo gallery.
              >> Most of the sites I've seen so far, only show the bare basics.
              >> With no real practical examples.
              >> As brucie does with his butterlies and bugs, he uses switch/case, but
              >> in
              >> php.[/color][/color]


              [color=blue]
              > The "switch/case" construct is the method of last resort, imho.
              > Mick[/color]

              I feel that in my situation, I may have to.
              It beats writing out a long string of "if" statements.
              Which it is actually designed for as an alternative to "if".
              Besides, I can follow the "case" elements easier.


              Comment

              • McKirahan

                #8
                Re: Switch/case how to use it correctly

                "Richard" <Anonymous@127. 001> wrote in message
                news:ctgkuf011o j@news2.newsguy .com...[color=blue]
                > On Sat, 29 Jan 2005 18:09:53 GMT Mick White wrote:
                >[color=green]
                > > Richard wrote:[/color]
                >[color=green][color=darkred]
                > >> I've been looking at implementing switch/case on my photo gallery.
                > >> Most of the sites I've seen so far, only show the bare basics.
                > >> With no real practical examples.
                > >> As brucie does with his butterlies and bugs, he uses switch/case, but
                > >> in
                > >> php.[/color][/color]
                >
                >
                >[color=green]
                > > The "switch/case" construct is the method of last resort, imho.
                > > Mick[/color]
                >
                > I feel that in my situation, I may have to.
                > It beats writing out a long string of "if" statements.
                > Which it is actually designed for as an alternative to "if".
                > Besides, I can follow the "case" elements easier.
                >[/color]

                Tell us what you're working with so we can be of more help.

                Do you have a list of URLs for the thumbnail images and corresponding URLs
                for the enlarged versions plus a description of each?

                For example,



                Google.Logo


                Comment

                • Richard

                  #9
                  Re: Switch/case how to use it correctly

                  On Sat, 29 Jan 2005 13:13:25 -0600 McKirahan wrote:
                  [color=blue]
                  > "Richard" <Anonymous@127. 001> wrote in message
                  > news:ctgkuf011o j@news2.newsguy .com...[color=green]
                  >> On Sat, 29 Jan 2005 18:09:53 GMT Mick White wrote:[/color][/color]
                  [color=blue][color=green][color=darkred]
                  >> > Richard wrote:[/color][/color][/color]
                  [color=blue][color=green][color=darkred]
                  >> >> I've been looking at implementing switch/case on my photo gallery.
                  >> >> Most of the sites I've seen so far, only show the bare basics.
                  >> >> With no real practical examples.
                  >> >> As brucie does with his butterlies and bugs, he uses switch/case,[/color]
                  >> but[color=darkred]
                  >> >> in
                  >> >> php.[/color][/color][/color]


                  [color=blue][color=green][color=darkred]
                  >> > The "switch/case" construct is the method of last resort, imho.
                  >> > Mick[/color][/color][/color]
                  [color=blue][color=green]
                  >> I feel that in my situation, I may have to.
                  >> It beats writing out a long string of "if" statements.
                  >> Which it is actually designed for as an alternative to "if".
                  >> Besides, I can follow the "case" elements easier.[/color][/color]

                  [color=blue]
                  > Tell us what you're working with so we can be of more help.[/color]
                  [color=blue]
                  > Do you have a list of URLs for the thumbnail images and corresponding
                  > URLs
                  > for the enlarged versions plus a description of each?[/color]
                  [color=blue]
                  > For example,[/color]
                  [color=blue]
                  > http://www.google.com/images/google_sm.gif
                  > http://www.google.com/images/logo.gif
                  > Google.Logo[/color]







                  Comment

                  • Robert

                    #10
                    Re: Switch/case how to use it correctly

                    In article <ctgpcd015sr@ne ws2.newsguy.com >,
                    "Richard" <Anonymous@127. 001> wrote:
                    [color=blue]
                    >
                    > www.somestuff.batcave.net/menu1.html[/color]

                    Here is a possibility.

                    The code may be a little hard to follow because it uses document.write
                    to generate the html. I did this because I got tired of typing out all
                    the long web addresses. To see the generated html, look for the term
                    one liner in this forum. The one line javascript program will show you
                    the generated html.

                    Some of the url's are long. Hope they come out.

                    Robert

                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
                    <html>
                    <head>
                    <title>Swap images</title>
                    <style type="text/css">

                    #footer{
                    clear: both;
                    padding-left: 20px;
                    padding-right: 20px;
                    padding-top: 5px;
                    padding-bottom: 5px;
                    background: #eee;
                    }

                    ..hide { display: none }

                    </style>

                    <script type="text/javascript">
                    var nasaPath = "http://spaceplace.nasa .gov" +
                    "/en/educators/images/solarsystem/";

                    var imageCount = 0;

                    /* I am using NASA images.
                    The thumbs have the suffix _T
                    The full size image has the suffix _L

                    I pass the image name without the path and the suffix.

                    To indicate the first call, I pass three arguements. In
                    the first call, I do not generate the tr tags.

                    */

                    function genImage(link,r ollover,msg)
                    {
                    // The first row has the full size image, so the
                    // tr tag is coded below.

                    // For the second image and all further images, code
                    // the tr tags.
                    if (arguments.leng th == 3)
                    { document.writel n("<tr>");}

                    var data = "<td width='110' valign='top'>" +
                    "<a href='" + nasaPath + link + "_L.jpg'>\n " +
                    "<img id='image" + imageCount + "'" +
                    "src='" + nasaPath + link + "_T.jpg'\n" +
                    "onclick='retur n changeImg(\"" +
                    nasaPath + link + "_L.jpg\",\ "" + msg + "\");'\n" +
                    "onmouseover='s etThumb(\"image " + imageCount +
                    "\",\"" + nasaPath + rollover + "_T.jpg\")' \n" +
                    "onmouseout='se tThumb(\"image" + imageCount +
                    "\",\"" + nasaPath + link + "_T.jpg\")' \n" +
                    ">\n" +
                    "<\/a></td>";
                    imageCount++
                    document.writel n(data);

                    // End tr tag
                    if (arguments.leng ht == 3)
                    { document.writel n("<\/tr>");}

                    }

                    function changeImg(name, msg)
                    {

                    document.images["big_image"].src =

                    "http://spaceplace.jpl. nasa.gov/en/_images/common/nasa_header/logo_nasa.g
                    if";
                    document.images["big_image"].src = name;
                    changeText('tex t',msg);
                    return false;
                    }

                    function setThumb(id,nam e)
                    {
                    document.images[id].src = name;
                    }

                    function changeText(labe l,text)
                    {

                    var node;
                    if (document.getEl ementById)
                    {
                    var node = document.getEle mentById(label) ;
                    if (node)
                    {

                    node.innerHTML = text;
                    return; /*See if we already inserted a node. */

                    }
                    else
                    {
                    alert("You need to create a span tag with " +

                    "the id of " + label + ".");
                    return;
                    }
                    }
                    else
                    {
                    alert(" document.getEle mentByID failed. " +
                    "You need to use a newer browser.");
                    return;
                    }

                    }

                    </script>
                    </head>
                    <body>
                    <h1 style="text-align: center;">Solar System</h1>
                    <table>
                    <tr>
                    <script type="text/javascript">
                    genImage("Mercu ryglobe1","Merc uryglobe2","Pla net Mercury","first ");

                    </script> <td width="600" height="800" align="center" valign="top"
                    rowspan="7">
                    <img id="big_image"
                    src="

                    f"[color=blue]
                    >[/color]
                    <br><span id='text'>Repla cement text here...</span>
                    </td>
                    </tr>

                    <script type="text/javascript">
                    genImage("Venus ","venusglobe", "Planet Venus");
                    genImage("clem_ full_moon","Ear th_moon","Earth &#039;s moon");
                    </script> </table>
                    <div id="footer">
                    <p>These image are from NASA. See:<br>

                    </p>
                    </div>

                    <script type="text/javascript">
                    // Preload the rollover images.
                    var selimage = new Image();
                    selimage.src = nasaPath + "Mercuryglobe2_ T.jpg";
                    var selimage = new Image();
                    selimage.src = nasaPath + "venusglobe_T.j pg";
                    var selimage = new Image();
                    selimage.src = nasaPath + "Earth_moon_T.j pg";
                    var selimage = new Image();
                    selimage.src = nasaPath + "marsglobe3_T.j pg";

                    </script>

                    </body>
                    </html>

                    Comment

                    • Richard

                      #11
                      Re: Switch/case how to use it correctly

                      On Sat, 29 Jan 2005 16:43:01 -0500 Robert wrote:
                      [color=blue]
                      > In article <ctgpcd015sr@ne ws2.newsguy.com >,
                      > "Richard" <Anonymous@127. 001> wrote:[/color]

                      [color=blue][color=green]
                      >> www.somestuff.batcave.net/menu1.html[/color][/color]
                      [color=blue]
                      > Here is a possibility.[/color]
                      [color=blue]
                      > The code may be a little hard to follow because it uses document.write
                      > to generate the html. I did this because I got tired of typing out all
                      > the long web addresses. To see the generated html, look for the term
                      > one liner in this forum. The one line javascript program will show you
                      > the generated html.[/color]

                      Thanks. Precisely what I do not want.
                      That's a bunch of needless work for what there is to do.
                      Why have a script write a table to begin with?
                      Use the script for what's inside the table.
                      IMNSHO, all of that work for the nasa site was wasted.
                      With JS off, it works just the same.

                      In my case, I need the image and description appearing below the thumbnails.
                      Outisde of an array probability, switch/case should be the answer.



                      Comment

                      • Randy Webb

                        #12
                        Re: Switch/case how to use it correctly

                        Richard wrote:[color=blue]
                        > On Sat, 29 Jan 2005 16:43:01 -0500 Robert wrote:
                        >
                        >[color=green]
                        >>In article <ctgpcd015sr@ne ws2.newsguy.com >,
                        >> "Richard" <Anonymous@127. 001> wrote:[/color]
                        >
                        >
                        >[color=green][color=darkred]
                        >>>www.somestuff.batcave.net/menu1.html[/color][/color]
                        >
                        >[color=green]
                        >>Here is a possibility.[/color]
                        >
                        >[color=green]
                        >>The code may be a little hard to follow because it uses document.write
                        >>to generate the html. I did this because I got tired of typing out all
                        >>the long web addresses. To see the generated html, look for the term
                        >>one liner in this forum. The one line javascript program will show you
                        >>the generated html.[/color]
                        >
                        >
                        > Thanks. Precisely what I do not want.
                        > That's a bunch of needless work for what there is to do.
                        > Why have a script write a table to begin with?
                        > Use the script for what's inside the table.
                        > IMNSHO, all of that work for the nasa site was wasted.
                        > With JS off, it works just the same.
                        >
                        > In my case, I need the image and description appearing below the thumbnails.
                        > Outisde of an array probability, switch/case should be the answer.[/color]

                        Neither is the answer. Not an array (unless the images/thumbnails are
                        not named coordinatedly). Read my other replies, it might come to you.

                        But to use a switch/case for what you want is like using a sledgehammer
                        to put a screw in the wall.



                        --
                        Randy
                        comp.lang.javas cript FAQ - http://jibbering.com/faq

                        Comment

                        • Robert

                          #13
                          Re: Switch/case how to use it correctly

                          You seem reluctant to go with people suggestions.

                          I used the table for formating reasons. I do not know the size of the
                          big picture. The table control acted the best when I had large and
                          small images, and when I resized the window. I tried using CSS and I
                          didn't like the results. When I resized the window to a small one, the
                          big image appeared below the small thumbs. I didn't like this. I have
                          another version with frames.
                          [color=blue]
                          > With JS off, it works just the same.[/color]
                          You sure you turned off javascript?

                          Mine is an example that should provide some clues how to do what you
                          want.

                          We need some more information on why you think a switch statement is
                          best.

                          Robert

                          Comment

                          • Robert

                            #14
                            Re: Switch/case how to use it correctly

                            Well, my web addresses got wrapped by my news reader program. I
                            usually use google, but it would have destroyed the formatting.

                            Robert

                            Comment

                            Working...