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

Thread: I need help

  1. #1
    Join Date
    Apr 2013
    Posts
    9

    I need help

    I am a designer,and recently tried to do a mini-game for a friend.I learned,or at least tried to learn java and jquery and am finished with most of the job.However,I want a dropdown list(made the layout already) and when you select something in there you can edit a variable's value (This sounds dumb but I don't normally use java).
    Here's my html:

    <ul id="menu">
    <li><a href="">In-game Minute</a>
    <ul>
    <li><a href="">Minute 15</a></li>
    <li><a href="">Minute 25</a></li>
    <li><a href="">Minute 35</a></li>
    <li><a href="">Minute 45</a></li>
    </ul>
    </li>
    <li><a href="">Champion Level</a>
    <ul>
    <li><a href="">Level 14</a></li>
    <li><a href="">Level 15</a></li>
    <li><a href="">Level 16</a></li>
    <li><a href="">Level 17</a><li>
    <li><a href="">Level 18</a><li>
    </ul>
    </li>
    </ul>



    And my CSS :


    ul {
    font-family: Arial, Verdana;
    font-size: 18px;
    margin: 1;
    padding: 1;
    list-style: none;
    }
    ul li {
    display: block;
    position: relative;
    float: right;
    }
    li ul { display: none; }
    ul li a {
    display: block;
    text-decoration: none;
    color: #ffffff;
    padding: 5px 15px 5px 15px;
    background: #2f2f2f;
    margin-left: 1px;
    white-space: nowrap;
    }
    ul li a:hover { background: #284266; }
    li:hover ul {
    display: block;
    position: absolute;
    }
    li:hover li {
    float: none;
    font-size: 11px;
    }
    li:hover a { background: #284266; }
    li:hover li a:hover { background: #284266; }



    How or what should I do in javascript so that if ( answer == 1 ) certainvariable=x;
    else if etc... ?

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

    Question

    Just a bit confused about your request ...

    1. Are you looking for a Java or JavaScript answer? You mention both in your original post. This is the "JavaScript" forum.

    2. What is the purpose of the "menu"> You do not have any links associated with the href assignments.

    3. To what answer are you referring to that should be checked == 1? Where do you make that assignment?

    BTW: You should enclose your script between [ code] and [ /code] tags (without the spaces) to make it easier
    for forum members to read, copy and test your attempts. It also preserves formatting of the display.

  3. #3
    Join Date
    Apr 2013
    Posts
    9
    1. Javascript.
    2. I got part of the dropdown list from an online lesson,because,as I said I learnt javascript briefly in about 1 day.I normally code in C.So anything that seems about of place you can tell me and how to edit it.
    3.Well I suck at explaining but here's what I want to do:
    Have a dropdown list and make the user select an option from it.How can I now go and do cases in javascript?IMO they should like this:
    [code]
    if( dropdownoption == 1 ){
    variable=10;
    }
    else if( dropdownoption == 2 ){
    variable=50;
    }
    etc..
    But I don't really know how to add that "dropdownoption" in my code.

  4. #4
    Join Date
    Apr 2013
    Posts
    9
    Seriously ? can nobody tell me ? I don't think it's so much code but I can't find anywhere.

  5. #5
    Join Date
    Apr 2013
    Posts
    9
    Sorry for spamming but unfortuantely I cannot edit my comments.This is the dropdown menu isolated from the rest of the code:
    http://jsfiddle.net/Kolume/mNyKE/58/
    What should I do in the javascript section so that I find out what the user has clicked and then have cases depending on that?

  6. #6
    Join Date
    Apr 2013
    Posts
    9
    Bump?

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,262
    I don't know if this will help or not because I'm still confused as to your final product.

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title> Untitled </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <style type="text/css">
    ul {
      font-family: Arial, Verdana;
      font-size: 18px;
      margin: 1;
      padding: 1;
      list-style: none;
    }
    ul li {
      display: block;
      position: relative;
      float: right;
    }
    li ul { display: none; }
    ul li a {
      display: block;
      text-decoration: none;
      color: #ffffff;
      padding: 5px 15px 5px 15px;
      background: #2f2f2f;
      margin-left: 1px;
      white-space: nowrap;
    }
    ul li a:hover { background: #284266; }
    li:hover ul {
      display: block;
      position: absolute;
    }
    li:hover li {
      float: none;
      font-size: 11px;
    }
    li:hover a { background: #284266; }
    li:hover li a:hover { background: #284266; }
    
    </style>
    
    </head>
    <body>
    <ul id="menu">
     <li><a href="#" onclick="Msg('0');return false">In-game Minute</a>
      <ul>
       <li><a href="#" onclick="Msg('1');return false">Minute 15</a></li>
       <li><a href="#" onclick="Msg('2');return false">Minute 25</a></li>
       <li><a href="#" onclick="Msg('3');return false">Minute 35</a></li>
       <li><a href="#" onclick="Msg('4');return false">Minute 45</a></li>
      </ul>
     </li>
     <li><a href="3" onclick="Msg('5');return false">Champion Level</a>
      <ul>
       <li><a href="#" onclick="Msg('6');return false">Level 14</a></li>
       <li><a href="#" onclick="Msg('7');return false">Level 15</a></li>
       <li><a href="#" onclick="Msg('8');return false">Level 16</a></li>
       <li><a href="#" onclick="Msg('9');return false">Level 17</a></li>
       <li><a href="#" onclick="Msg('10');return false">Level 18</a></li>
      </ul>
     </li>
    </ul>
    
    <div id="ActionBlock"></div>
    
    <script type="text/javascript">
    var Messages = [
     'In-Game Minute',
       'Minute 15',  'Minute 25',  'Minute 35',  'Minute 45',
     'Champion Level',
       'Level 14',  'Level 15',  'Level 16',  'Level 17',  'Level 18'
    ];
    
    function Msg(N) {
    //  alert(Messages[N]);  // Do something here based upon message clicked (???)
      document.getElementById('ActionBlock').innerHTML = Messages[N];
    }
    </script>
    
    </body>
    </html>

  8. #8
    Join Date
    Apr 2013
    Posts
    9
    Can you please do that in jsfiddle?
    I tried to do it but it doesn't work(gives errors if I implement it the way you put it,jsfiddle has separate columns for each language)

  9. #9
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,262

    Lightbulb

    Quote Originally Posted by Kolor View Post
    Can you please do that in jsfiddle?
    I tried to do it but it doesn't work(gives errors if I implement it the way you put it,jsfiddle has separate columns for each language)
    I don't use jsfiddle. Too confusing to me what it is that they are trying to do.

    Just copy the posted information to a local file (filename.html) on your computer and open your browser to that file.

    Whole lot easier than 'fiddle'ing around with that site.

    You could also drop it into your server, change access permisisons if necessary, and open your browser to that file.

    Note: Keep in mind that the post is just a suggestion as I'm still guessing what it is that you are trying to accomplish!

  10. #10
    Join Date
    Apr 2013
    Posts
    9
    I just want to get cases from everything and edit a variable accordingly.I just don't understand why splitting the code into javascript,html and css makes it not work.

  11. #11
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,262
    Quote Originally Posted by Kolor View Post
    I just want to get cases from everything and edit a variable accordingly.I just don't understand why splitting the code into javascript,html and css makes it not work.
    What are the "cases" you are trying to get?

    What variable are you trying to edit?
    What do you want to do with this variable?
    Please, in english, describe what your program is attempting to do.
    I did not take the mind-reading course in college.



    You should be able to split the CSS and Javascript code from the HTML. Place them into external files (.css and .js respectively)
    Make sure you DO NOT include any HTML tags in the external files.
    In the HTML, use the <link ... > and <script ..... src="filename.js" ...> tags to load the CSS and JS files.

  12. #12
    Join Date
    Apr 2013
    Posts
    9
    Just take a look at this:
    http://jsfiddle.net/Kolume/JUgab/11/
    I only did the cases for level selection.So for example,if you choose 14,I want that next to the hand image down,right before damage to type for example,the level selected times,let's say 50 and store that into a var.
    Can you edit it so it does that?

  13. #13
    Join Date
    Apr 2013
    Posts
    11
    You can write:

    <li><a href="" onclick="setLevel(14)">Level 14</a></li>

    in Javascript:
    var myLevel;
    function setLevel(level){
    myLevel = 14;
    }

    Since you are going to add different value for each level, I think this might be the solution.
    Once myLevel variable is set, you can display it either wrap it inside a div tag using jquery or append after specific html element.

  14. #14
    Join Date
    Apr 2013
    Posts
    9
    @dennist82 I love you man.

  15. #15
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,253
    It's also possible to use a select tag See this page

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