Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Alert box in drop down HTML

    I'm taking an entry level CS course. While I realize this question is simple it goes past what our professor has taught this class. I've taken pascal, and C++ in highschool and I think I could do better than most of the clowns in here. If you don't want to give me the answer that's cool you'd rather pick my brain.

    What i'm trying to do - ask the user a question. There's a drop down box that has possible answers. If they click on the right one I tell them via alert box. Else I tell them their answer was wrong.

    Here's my script

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Writing Intervals</title>
    </head>

    <body>

    There are two things to take into consideration when writing intervals. The first is the number, which is determined
    by the distance between the letters. Here are some examples of this first part
    <ul>
    <li>C-C is a unison
    <li>C-D is a second <em>think c(first) d (second)</em>
    <li>C-E is a third <em>think c(first) d (second) e (third)</em>

    <li>C-G is a fifth
    <li>F-A is a third
    </ul>

    Let's see if you understand this. Here are some examples for you to try.

    <ol>
    <li>G to G would be a
    <select>
    <option>Unison</option>
    <option>Second</option>
    <option>Third</option>

    <option>Fourth</option>
    <option>Fifth</option>
    <option>Sixth</option>
    <option>Seventh</option>
    </select>
    <li>G to A would be a
    <select>
    <option>Unison</option>

    <option>Second</option>
    <option>Third</option>
    <option>Fourth</option>
    <option>Fifth</option>
    <option>Sixth</option>
    <option>Seventh</option>

    </select>
    <li>B to D would be a
    <select>
    <option>Unison</option>
    <option>Second</option>
    <option>Third</option>
    <option>Fourth</option>
    <option>Fifth</option>

    <option>Sixth</option>
    <option>Seventh</option>
    </select>
    <ol>

    </body>
    </html>

  • #2
    New Coder
    Join Date
    Oct 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    just noticed I didn't close out the ol tag at the end. I need to proof all this on my own, but if someone could help me with my question that would be cool.

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,292
    Thanks
    4
    Thanked 202 Times in 199 Posts
    To make it easier for us "clowns" to help you what have you tried that isn't working the way you want it to?
    Dave .... HostMonster for all of your hosting needs

  • #4
    Regular Coder godofreality's Avatar
    Join Date
    Jan 2009
    Posts
    234
    Thanks
    1
    Thanked 15 Times in 15 Posts
    your issue your in need of help is a javascript deal basically u need to add an event to your <select> tags u being a c++ coder should know what an event is but basically u want
    Code:
    //use the onchange event to call up the getAnswer function created in javascript and give each <select> tag an id so the function knows which dropdown is sending the user answe from and add a value to each option so they have a value not sure how to put that lol and created a blank option as the default option
    
    <select onchange="getAnswer(this)" id="1">
    <option value=""></option>
    <option value="unison">Unison</option>
    <option value="second">Second</option>
    <option value="third">Third</option>
    <option value="fourth">Fourth</option>
    <option value="fifth">Fifth</option>
    <option value="sixth">Sixth</option>
    <option value="seventh">Seventh</option>
    </select>
    
    <li>G to A would be a
    <select onchange="getAnswer(this)" id="2">
    <option value=""></option>
    <option value="unison">Unison</option>
    <option value="second">Second</option>
    <option value="third">Third</option>
    <option value="fourth">Fourth</option>
    <option value="fifth">Fifth</option>
    <option value="sixth">Sixth</option>
    <option value="seventh">Seventh</option>
    </select>
    
    <li>B to D would be a
    <select onchange="getAnswer(this)" id="3">
    <option value=""></option>
    <option value="unison">Unison</option>
    <option value="second">Second</option>
    <option value="third">Third</option>
    <option value="fourth">Fourth</option>
    <option value="fifth">Fifth</option>
    <option value="sixth">Sixth</option>
    <option value="seventh">Seventh</option>
    </select>
    and for the javascript
    Code:
    <script type="text/javascript">
    function getAnswer(thisSelect)
    {
    with(thisSelect)
    {
    switch(id)
    {
    case 1:
    //this is for question 1
    if(value == "the correct answer"){ alert("Correct");}else{ alert("Incorrect");}
    break;
    
    case 2:
    //question 2
    if(value == "the correct answer"){ alert("Correct");}else{ alert("Incorrect");}
    break;
    
    case 3:
    //question 3
    if(value == "the correct answer"){ alert("Correct");}else{ alert("Incorrect");}
    break;
    }
    }
    }

  • Users who have thanked godofreality for this post:

    ba7159 (10-22-2009)

  • #5
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Durrrrrr! Me am big smart C++ man but me can't code dirt simple javascript. You am all dumb-dumb though!

    Have a nice life with that attitude, cool guy!
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #6
    New Coder
    Join Date
    Oct 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Rowsdower! View Post
    Durrrrrr! Me am big smart C++ man but me can't code dirt simple javascript. You am all dumb-dumb though!

    Have a nice life with that attitude, cool guy!
    I'm not familiar with javascript. I may have given the wrong impression - I don't think C++ is more difficult than other languages...it's all about the nuances, the thought process is the same. Obviously I'm so inexperienced with javascript that I came here looking for help. Normally I can google my way out of problems. Yes it's dirt simple...one more trick to add to the bag.

  • #7
    New Coder
    Join Date
    Oct 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Rowsdower! View Post
    Durrrrrr! Me am big smart C++ man but me can't code dirt simple javascript. You am all dumb-dumb though!

    Have a nice life with that attitude, cool guy!
    Reread my post. Dude I'm saying the clowns in my class. This is an intro class - i'm trying to use it as an opportunity to get better.
    Last edited by ba7159; 10-23-2009 at 02:07 AM.


  •  

    Posting Permissions

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