www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Need help....switch/case

  1. #1
    Join Date
    Jul 2014
    Posts
    8

    Need help....switch/case

    I bloody Java beginner and just do not get ahead: goal is to access a variable "saskia" from the context (output) with the values ​​1-5 and display a corresponding image. That means: If the output saskia = 1 the Fig.1 should be displayed on the page, is the output saskia = 2 the Fig.2 should be displayed on the page, etc.

    It just does not work ... do you know what could be wrong? Thanks for your answers.
    Code:
    <html lang="de">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Fa_Pferdestärken</title>
    
    </head>
    
    <body>
    
    <!-- Sichtbarer Dokumentinhalt im body -->
    <h1 style= "color:orange; font-size:50px" > Firma Pferdestärken </h1>
    <p style= "color:orange; font-size:35px" > Inhaber Klaus Raser </p>
    <h2 style= "color:green; font-size:40px" > Ihr Partner für Auto- und Motorradzubehör</h2>
    
    
    <p> In Kooperation mit:
    <a href="Startseite.html">Tempolimit GmbH, HH
    </a> 
    
    </p>
    
    <script type="text/javascript">
    document.write('<scr'+'ipt type=\"text/javascript\" src=\"http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"><\/scr'+'ipt>');
    
    
    document.addEventListener("DOMContentLoaded", function(event) { 
    int saskia;
    saskia=5;
    switch(saskia) {
    case 1:
    newImage('<img src="moto1.jpg">');
    break;
    case 2:
    newImage('<img src="auto1.jpg">');
    break;
    case 3:
    newImage('<img src="Städtereisen.jpg">');
    break;
    case 4:
    newImage('<img src="Tastenhandy.jpg">');
    break;
    case 5:
    newImage('<img src="Waschmittel.jpg">');
    break;
    
    }
    
    });
    
    </script> 
    </body>
    
    </html>
    Also, I get the error message: "missing; before statement" in the line with var = Saskia
    Last edited by jedaisoul; 07-16-2014 at 12:51 PM. Reason: added code tags

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434

    Lightbulb

    Untested due to lack of image pathway. Set the 'baseURL' to the image location.

    'int' is not an assigment keyword in Javascript
    Also note that the image will never change with current assignment of "var saskia = 5" only,
    but I'm unclear as to final design desires because I cannot read the language.


    Code:
    <html lang="de">
    <head>
    <meta http-equiv="content-type" content="text/html" charset="utf-8">
    <title>Fa_Pferdestärken</title>
    </head>
    <body>
    
    <!-- Sichtbarer Dokumentinhalt im body -->
    <h1 style= "font-size:50px"> Firma Pferdestärken </h1>
    <p style= "font-size:35px"> Inhaber Klaus Raser </p>
    <h2 style= "color:green; font-size:40px"> Ihr Partner für Auto- und Motorradzubehör</h2>
    
    <p> In Kooperation mit:
    <a href="Startseite.html">Tempolimit GmbH, HH</a>
    </p>
    
    <img id="mainImg" src="moto1.jpg" alt="moto1.jpg">
    
    <script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script>
    <script type="text/javascript">
    // better to load directly than use the document.write here
    // document.write('<scr'+'ipt type=\"text/javascript\" src=\"http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"><\/scr'+'ipt>');
    
    
    document.addEventListener("DOMContentLoaded", function(event) {
      var baseURL = '';  // set path to where images are located
      var imgSource;
      var saskia = 5;  // note: nothing will change with this assignment every time!!!
    
      switch (saskia) {
        case 1 : imgSource = "moto1.jpg"; break;
        case 2 : imgSource = "auto1.jpg"; break;
        case 3 : imgSource = "Städtereisen.jpg"; break;
        case 4 : imgSource = "Tastenhandy.jpg"; break;
        case 5 : imgSource = "Waschmittel.jpg"; break;
        default: imgSource = 'moto1.jpg'; break;
      }
      document.getElementById('mainImg').src = baseURL+imgSource;
      document.getElementById('mainImg').alt = imgSource;
    
    });
    
    </script>
    </body>
    
    </html>
    BTW: You should enclose your code between [ code] and [ /code] tags (without the spaces)
    to make it easier to read, copy, debug and correct your scripts. It also preserves your formatting.

  3. #3
    Join Date
    Jul 2014
    Posts
    8
    Thanks,

    The Output "saskia" gives me a value, so I would like to refer me, so only "var saskia".
    Unfortunately, there is only the image moto.jpg shown now, and not variable images...depending on the output
    Here is my code:
    Code:
    <html lang="de">
    <head>
    <meta http-equiv="content-type" content="text/html" charset="utf-8">
    <title>Fa_Pferdestärken</title>
    </head>
    <body>
    
    <!-- Sichtbarer Dokumentinhalt im body -->
    <h1 style= "font-size:50px"> Firma Pferdestärken </h1>
    <p style= "font-size:35px"> Inhaber Klaus Raser </p>
    <h2 style= "color:green; font-size:40px"> Ihr Partner für Auto- und Motorradzubehör</h2>
    
    <p> In Kooperation mit:
    <a href="Startseite.html">Tempolimit GmbH, HH</a>
    </p>
    
    <img id="mainImg" src="moto1.jpg" alt="moto1.jpg">
    
    
    <script type="text/javascript" src="http://stage3.nuggad.net/rc?nuggn=546037980&nuggsid=2085598842"></script>
    <script type="text/javascript">
    // better to load directly than use the document.write here
    // document.write('<scr'+'ipt type=\"text/javascript\" src=\"http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"><\/scr'+'ipt>');
    
    
    
    document.addEventListener("DOMContentLoaded", function(event) {
      var baseURL = '';  // set path to where images are located --> its the same folder 
      var imgSource;
      var saskia;  // note: nothing will change with this assignment every time!!!
    
      switch (saskia) {
        case 1 : imgSource = "moto1.jpg"; break;
        case 2 : imgSource = "auto1.jpg"; break;
        case 3 : imgSource = "Städtereisen.jpg"; break;
        case 4 : imgSource = "Tastenhandy.jpg"; break;
        case 5 : imgSource = "Waschmittel.jpg"; break;
        default: imgSource = 'moto1.jpg'; break;
      }
      document.getElementById('mainImg').src = baseURL+imgSource;
      document.getElementById('mainImg').alt = imgSource;
    
    });
    
    </script>
    </body>
    
    </html>
    Last edited by jedaisoul; 07-16-2014 at 12:53 PM. Reason: code tags added

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434
    Does not look like you changed very much.

    Note that the only image that can be displayed now is the 'moto1.jpg', assuming it is in the 'baseURL' pathway
    because it is the default display of the switch command.

    I do not see anywhere you are changing the value of 'saskia' and in fact, it is only ever initialized to an undefined value by the 'var saskia;' command.
    There will be no other images shown until saskia is changed somewhere in the program.
    Where do you change the value of saskia for the switch command to be effected?

    Remember to use the [ code] and [ /code] tags please...
    Code:
    <html lang="de">
    <head>
    <meta http-equiv="content-type" content="text/html" charset="utf-8">
    <title>Fa_Pferdestärken</title>
    </head>
    <body>
    
    <!-- Sichtbarer Dokumentinhalt im body -->
    <h1 style= "font-size:50px"> Firma Pferdestärken </h1>
    <p style= "font-size:35px"> Inhaber Klaus Raser </p>
    <h2 style= "color:green; font-size:40px"> Ihr Partner für Auto- und Motorradzubehör</h2>
    
    <p> In Kooperation mit:
    <a href="Startseite.html">Tempolimit GmbH, HH</a>
    </p>
    
    <img id="mainImg" src="moto1.jpg" alt="moto1.jpg"> <p>
    <button onclick="alterImage(this.value)" value="1">Moto</button>
    <button onclick="alterImage(this.value)" value="2">Auto</button>
    <button onclick="alterImage(this.value)" value="3">Städtereisen</button>
    <button onclick="alterImage(this.value)" value="4">Tastenhandy</button>
    <button onclick="alterImage(this.value)" value="5">Waschmittel</button>
    
    
    <!-- script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script -->
    <!-- above not given for testing -->
    
    <script type="text/javascript">
    // better to load directly than use the document.write here
    // document.write('<scr'+'ipt type=\"text/javascript\" src=\"http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"><\/scr'+'ipt>');
    
    
    document.addEventListener("DOMContentLoaded", function(event) {
      var saskia = 5;  // note: nothing will change with this assignment every time!!!
    });
    
    function alterImage(saskia) {
      var baseURL = '';  // set path to where images are located
      var imgSource;
      switch (saskia) {
        case '1' : imgSource = "moto1.jpg"; break;
        case '2' : imgSource = "auto1.jpg"; break;
        case '3' : imgSource = "Städtereisen.jpg"; break;
        case '4' : imgSource = "Tastenhandy.jpg"; break;
        case '5' : imgSource = "Waschmittel.jpg"; break;
         default : imgSource = 'moto1.jpg'; break;
      }
      document.getElementById('mainImg').src = baseURL+imgSource;
      document.getElementById('mainImg').alt = imgSource;
    }
    
    </script>
    </body>
    
    </html>
    Last edited by JMRKER; 07-15-2014 at 02:06 PM.

  5. #5
    Join Date
    Jul 2014
    Posts
    8
    good morning, that's my problem. I do not know how I can declare the variable saskia. It is located in the output and returns values ​​between 1-5. Depending on the value a corresponding image should be displayed. I'm sorry I am a bluddy beginner, if I could, I would make more.

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434
    Quote Originally Posted by Sasserl View Post
    good morning, that's my problem. I do not know how I can declare the variable saskia. It is located in the output and returns values ​​between 1-5. Depending on the value a corresponding image should be displayed. I'm sorry I am a bluddy beginner, if I could, I would make more.
    What "output" are you referring toward?
    Where does the variable get set or changed by the program or user?
    Is it a button for the user to click on that sets the variable to a value of 1-5
    or is it a timed sequence that displays the images for a period of time while advancing the 'saskia' variable value?

  7. #7
    Join Date
    Jul 2014
    Posts
    8
    Quote Originally Posted by JMRKER View Post
    What "output" are you referring toward?
    Where does the variable get set or changed by the program or user?
    Is it a button for the user to click on that sets the variable to a value of 1-5
    or is it a timed sequence that displays the images for a period of time while advancing the 'saskia' variable value?
    The output work that way: 2 pages are joined together. If the user clicks on page A on a motorcycle category, the output saskia recognize this and returns for example the result "saskia=3" in the Output the page B should be able to read the output and should display a motorcycle image.

    the output is in here:
    Code:
    <!-- script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script -->
    when the output saskia = 1 the image "moto1.jpg" should be shown when output saskia = 2 "auto1.jpg" and so on...

  8. #8
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434
    That last bit of code for the script is commented out and is not used as typed.
    Will be a problem if in the working code version.

  9. #9
    Join Date
    Jul 2014
    Posts
    8
    Quote Originally Posted by JMRKER View Post
    That last bit of code for the script is commented out and is not used as typed.
    Will be a problem if in the working code version.
    do you have an idea how i can handle with this?

  10. #10
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434

    Arrow

    Quote Originally Posted by Sasserl View Post
    do you have an idea how i can handle with this?
    Uncomment the code from:
    Code:
    <!-- script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script -->
    to:
    Code:
    <script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script>

  11. #11
    Join Date
    Jul 2014
    Posts
    8
    Quote Originally Posted by JMRKER View Post
    Uncomment the code from:
    Code:
    <!-- script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script -->
    to:
    Code:
    <script type="text/javascript" src="http://stage3.xxxx.net/rc?xxx=546037980&xxx=2085598842"></script>
    I had done so. the code has been displayed only wrong

  12. #12
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434
    I'm not sure from your comments what the problem currently is.
    Do you have a live site to look at now?

  13. #13
    Join Date
    Jul 2014
    Posts
    8
    Quote Originally Posted by JMRKER View Post
    I'm not sure from your comments what the problem currently is.
    Do you have a live site to look at now?
    Yes...there:

    /Users/sregenscheit/Documents/HTML/Fa_Pferdestärken.html

  14. #14
    Join Date
    Jul 2014
    Posts
    8
    Quote Originally Posted by Sasserl View Post
    Yes...there:

    /Users/sregenscheit/Documents/HTML/Fa_Pferdestärken.html
    oh sorry..this is the right page:
    http://test.nugg.ad/customers/Saskia...destärken.html

  15. #15
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,434

    Exclamation

    Quote Originally Posted by Sasserl View Post
    When I click on the link, I see a display I cannot read so I don't know what is supposed to be displayed.
    When I look at the source, I see that you are relying on the value of 'saskia' to be set in the switch command ...
    Code:
    document.addEventListener("DOMContentLoaded", function(event) {
      var baseURL = '';  // set path to where images are located
      var imgSource;
      var saskia ;  // note: nothing will change with this assignment every time!!!
    
      switch (saskia) {
    ...
    but you initialize it to nothing and then test it. Why???

    When I look at the external source of
    Code:
    <script type="text/javascript" src="http://stage3.nuggad.net/rc?nuggn=546037980&nuggsid=2085598842"></script>
    I see the following ...
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>404 Not Found</title>
    </head><body>
    <h1>Not Found</h1>
    <p>The requested URL /rc was not found on this server.</p>
    </body></html>
    ... which does absolutely nothing to the variable 'saskia'

    You might want to do some further testing
    and use the error console of FF or Chrome browsers
    or put in some specific error message code logic.

    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles