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 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help on a drop down menu

    I am fairly new to scripting, JavaScript, heck, I will admit it, coding of any sort.

    So, I am trying to make a dropdown menu that will generate at demand an empty frame, or two frames of various forms.

    I pieced together the following:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function go(form) 
    {
    location=form.selectmenu.value
    }
    </script>
    </head>
    
    <body>
    <form>
    <select name="selectmenu" onchange="switchframes()">
    	<iframe src="frameEmpty.htm" id="frame1">Empty</iframe>
    	<iframe src="frameSBA.htm" id="frame2">SBA</iframe>
    	<iframe src="frameStructuredBond.htm" id="frame3">Structured Bond</iframe>
    </select>
    </form>
    </body>
    
    </html>
    What is wrong here? Sorry if it is obvious, but I am really new to this and don't have a single clue as to what the problem could be.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Before you start with javascript, you need to learn HTML.
    An IFRAME is not a valid child of a SELECT element.
    If you're trying to make a new element, you need createElement and appendChild. (see the LI example here Adding <li> with DOM, which was posted right by your post on this page last I checked)
    You'd have the options in the select and then have the onchange of the select create the new element and append it to the document.

    Valid HTML becomes more important as you use javascript to manipulate the elements.
    You can see the HTML specs here

    HTH

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Pardon me but this is not really a matter of learning simple HTML, this is WAY beyond simple HTML, so don't give me the admonishing schoolteacher attitude. W3 School's tutorials are useless...

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    If you already knew HTML, you would have already known that iframes are not valid children of selects.
    Pardon me for trying to help.
    Have a nice day.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH
    If you already knew HTML, you would have already known that iframes are not valid children of selects.
    Pardon me for trying to help.
    Have a nice day.
    I said simple HTML. iframes are not basic or simple for that matter.

  • #6
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Is this something like what you are trying to do mate?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Iframe menu</title>
    <script>
    function doMenu(strLocation) {
    	if( strLocation.length > 0 ) {
    		document.getElementById("frmIframe").src = strLocation;
    	}
    }
    </script>
    </head>
    
    <body>
    <form name="frm">
      <select name="selMenu" onchange="doMenu(this.value)">
        <option value="" selected>Please select a link</option>
        <option value="http://www.codingforums.com">Coding Forums</option>
        <option value="http://www.dynamicdrive.com">Dynamic Drive</option>
        <option value="myPage.html">Another page</option>
      </select>
    </form>
    
    <iframe id="frmIframe" name="frmIframe" width="400" height="200" frameborder="1"></iframe>
    </body>
    </html>
    Hope this helps.

    m_n
    Last edited by martin_narg; 06-22-2005 at 05:45 PM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

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