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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alert Box and Menu Help!!! AGH!

    Okay..i have the drop down menu...and I'm trying to make it so when you select "choose a genre" or "-------" an alert box pops up saying "please choose"...I'm 99.99% sure that my error is in the javascript part of the html...thnx for helping a beginner!



    This is what I have:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Tom's Music Page</title>
    <link rel="stylesheet" type="text/css" href="intro.css" />
    
    <script language="Javascript">
    
    function go()
    {
    
    if ( location=document.drop.mus.option[document.drop.mus.selectedIndex].asdf return 
    
    alert('Choose Again');
    else
    location=document.drop.mus.options[document.drop.mus.selectedIndex].value;
    }
    
    
    </script>
    </head> 
    
    <body>
    
    <h1>Choose A Genre!</h1>
    </ br>
    <img src="piano.jpg" width="502" alt="" />
    <form name="drop">
    <select name="mus"  onChange="go()">
    <option value="asdf">Choose a Genre!</option>
    <option value="asdf">-------------</option>
    <option value="page1.html">Hip-Hop</option>
    <option value="page2.html">Alternative</option>
    <option value="page3.html">Classical</option>
    <option value="asdf">-------------</option>
    <option value="index.html">Home!</option>
    </select>
    
    
    
    </form>
    
    </body>
    </html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Code:
    function go(objSelect)
    {
        var val = objSelect.options[objSelect.selectedIndex].value;
        if (val=='asdf') {
            alert('Choose Again');
        }
        else {
            location.href=val;
        }
    }
    ...
    <select name="mus"  onChange="go(this)">
    Using the this keyword simplifies the function. It doesn't need to know what the form name and select name are.

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OMGOMGOMGOMG You did it!!! THnx!!!!!!! I owe you!!!


  •  

    Posting Permissions

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