Web Analytics Made Easy -
StatCounter javascript targeting frame from a menu - CodingForum

Announcement

Collapse
No announcement yet.

javascript targeting frame from a menu

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • javascript targeting frame from a menu

    I have a pull down menu that has all 50 states within it. When you click on an individual state I want it to open within a certain frame. This is the javascript I found and it works great for the menu.
    Is their a way to have it target a certain frame?

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>
    </head>
    <body>
    <form name="form1">
    <select name="State" onChange="MM_jumpMenu('parent',this,0)">
    <option selected>Choose Your State</option>
    <option value="states/alaska.htm">Alaska</option>
    <option value="states/alabama.htm">Alabama</option>
    <option value="states/arizona.htm">Arizona</option>

  • #2
    <select name="State" onChange="MM_jumpMenu('parent',this,0)">


    change 'parent' to your target frame name (leave the single quotes)

    Comment


    • #3
      When I try that I get and error on the page. Stating that 'ContentFrame' is undefined

      <form name="form1">
      <select name="State" onChange="MM_jumpMenu('ContentFrame',this,0)">
      <option selected>Choose Your State</option>
      <option value="states/alaska.htm">Alaska</option>
      <option value="states/alabama.htm">Alabama</option>
      <option value="states/arizona.htm">Arizona</option>

      Comment


      • #4
        Change the function to this:

        function MM_jumpMenu(targ,selObj,restore){ //v3.0
        window.open(selObj.options[selObj.selectedIndex].value, targ);
        if (restore) selObj.selectedIndex=0;
        }
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Hey Tm, I think I got an easy solution to your problem.

          <option value="states/alaska.htm">Alaska</option>

          I'm guessing that you're going to be using the value of this menu to provide the href portion of an anchor tag, right? If so, simply modify your end anchor like this:

          <A HREF="value of menu" TARGET="ContentFrame">

          This is much simpler than adding it into your function. If your function requires the name of the frame for other reasons, leave it in as Glenngv has shown.

          Geyegeroffe

          Comment


          • #6
            There are actually no anchor links. The select box serves as links that will open the page in the target frame.
            Last edited by glenngv; Feb 27, 2004, 04:38 AM.
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              Since it's currently 4:30am, I overlooked the fact that your function is the anchor I was talking about. Following is probably the simplest way to go:


              function MM_jumpMenu()
              {
              var number = document.form1.State.selectedIndex;
              document.ContentFrame.location.href = document.form1.States.options[number].value;
              }

              I'm not 100% sure that I'm referring to the frame Content Frame propperly, but it is definately easier than using the parent property...

              Geyegeroffe

              Comment

              Working...
              X