onselect open new window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Wahmann

    onselect open new window

    I'm having trouble with the following code appending the form name and an
    empty value to the end of the url. Can anyone tell me what's wrong? I
    appreciate any tips or advice you can pass along!

    Rob

    // submits info like this: http://www.google.com/?select=

    <script type="text/javascript">
    function launchIt() {
    var form = document.search ;
    var select = form.select;
    var option = select.options[select.selected Index];

    select.selected Index = 0;
    form.target = option.getAttri bute('name');
    form.action = option.value;
    form.submit();
    //form.target = '';
    //form.action = '';
    }
    </script>

    <form method="get" name="search">
    <select name="select" onChange="launc hIt()" style="font-size:9px">
    <option value="">Select Service</option>
    <option value="http://www.google.com/" name="google">G oogle</option>
    <option value="http://www.hotbot.com/" name="hotbot">H otbot</option>
    </select>
    </form>


  • Lee

    #2
    Re: onselect open new window

    Rob Wahmann said:[color=blue]
    >
    >I'm having trouble with the following code appending the form name and an
    >empty value to the end of the url. Can anyone tell me what's wrong? I
    >appreciate any tips or advice you can pass along!
    >
    >Rob
    >
    >// submits info like this: http://www.google.com/?select=[/color]

    That's what happens when you submit a form using "get".
    Your form elements and their values are appended to the URL.

    In this case, your only form element is named "select", and
    its value is "".

    It looks like you don't really want to submit anything, just
    open a window, so you should be using something more like:

    <script type="text/javascript">
    function launchIt(select ) {
    var option = select.options[select.selected Index];
    window.open(opt ion.value,optio n.getAttribute( 'name'));
    }
    </script>

    <form method="get" name="search">
    <select name="select" onChange="launc hIt(this)" style="font-size:9px">
    <option value="">Select Service</option>
    <option value="http://www.google.com/" name="google">G oogle</option>
    <option value="http://www.hotbot.com/" name="hotbot">H otbot</option>
    </select>
    </form>

    Comment

    • Rob Wahmann

      #3
      Re: onselect open new window

      That works great! I should have been clearer in my last message... I knew
      why it was happening but I didn't know how to resolve it. Thanks for the
      assistance.

      I have only one more question... How can I make the form do nothing if the
      option value is empty ""? Thanks again for your help!

      Rob

      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:c2b0gd0ioc @drn.newsguy.co m...[color=blue]
      > Rob Wahmann said:[color=green]
      > >
      > >I'm having trouble with the following code appending the form name and an
      > >empty value to the end of the url. Can anyone tell me what's wrong? I
      > >appreciate any tips or advice you can pass along!
      > >
      > >Rob
      > >
      > >// submits info like this: http://www.google.com/?select=[/color]
      >
      > That's what happens when you submit a form using "get".
      > Your form elements and their values are appended to the URL.
      >
      > In this case, your only form element is named "select", and
      > its value is "".
      >
      > It looks like you don't really want to submit anything, just
      > open a window, so you should be using something more like:
      >
      > <script type="text/javascript">
      > function launchIt(select ) {
      > var option = select.options[select.selected Index];
      > window.open(opt ion.value,optio n.getAttribute( 'name'));
      > }
      > </script>
      >
      > <form method="get" name="search">
      > <select name="select" onChange="launc hIt(this)" style="font-size:9px">
      > <option value="">Select Service</option>
      > <option value="http://www.google.com/" name="google">G oogle</option>
      > <option value="http://www.hotbot.com/" name="hotbot">H otbot</option>
      > </select>
      > </form>
      >[/color]


      Comment

      • Randy Webb

        #4
        Re: onselect open new window

        Rob Wahmann wrote:[color=blue]
        > That works great! I should have been clearer in my last message... I knew
        > why it was happening but I didn't know how to resolve it. Thanks for the
        > assistance.
        >
        > I have only one more question... How can I make the form do nothing if the
        > option value is empty ""? Thanks again for your help![/color]


        <script type="text/javascript">
        function launchIt(select ) {
        var option = select.options[select.selected Index];
        if (option != ''){
        window.open(opt ion.value,optio n.getAttribute( 'name'));
        }
        }
        </script>
        --
        Randy
        Chance Favors The Prepared Mind
        comp.lang.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • Rob Wahmann

          #5
          Re: onselect open new window

          Hmm... I see where you're going with this but it still allows me to submit
          empty values. Thanks for the assistance!

          Rob
          [color=blue]
          > <script type="text/javascript">
          > function launchIt(select ) {
          > var option = select.options[select.selected Index];
          > if (option != ''){
          > window.open(opt ion.value,optio n.getAttribute( 'name'));
          > }
          > }
          > </script>
          > --
          > Randy
          > Chance Favors The Prepared Mind
          > comp.lang.javas cript FAQ - http://jibbering.com/faq/[/color]


          Comment

          • Randy Webb

            #6
            Re: onselect open new window

            Rob Wahmann wrote:

            Top posting fixed - please read the FAQ with regards to top-posting,
            quoting and snipping.
            [color=blue][color=green]
            >><script type="text/javascript">
            >> function launchIt(select ) {
            >> var option = select.options[select.selected Index];
            >> if (option != ''){
            >> window.open(opt ion.value,optio n.getAttribute( 'name'));
            >> }
            >> }
            >></script>[/color]
            > Hmm... I see where you're going with this but it still allows me to submit
            > empty values. Thanks for the assistance!
            >[/color]

            "submit empty values" ?? You are not submitting a form, you are simply
            opening a new window with a URL parameter. The parameter happens to be a
            variable scenario that mimics a form post. To verify that, put an
            onsubmit="alert ('I am submitting')" on the form and see if you see it.
            Using the above script, you won't. And as written, its not even
            appending the variables, its simply opening a new window with the URL
            set to the select value, and the name of the window being the same as
            the "name" attribute of the option that was chosen at the time.

            Perhaps a little more explanation of what you are trying to do?
            Submitting a search to google takes a little more than what you are doing.

            --
            Randy
            Chance Favors The Prepared Mind
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            • Rob Wahmann

              #7
              Re: onselect open new window

              "Randy Webb" <hikksnotathome @aol.com> wrote in message
              news:8sydnZBqLK xI0dfdRVn-iQ@comcast.com. ..[color=blue]
              > Rob Wahmann wrote:
              >
              > Top posting fixed - please read the FAQ with regards to top-posting,
              > quoting and snipping.
              >[color=green][color=darkred]
              > >><script type="text/javascript">
              > >> function launchIt(select ) {
              > >> var option = select.options[select.selected Index];
              > >> if (option != ''){
              > >> window.open(opt ion.value,optio n.getAttribute( 'name'));
              > >> }
              > >> }
              > >></script>[/color]
              > > Hmm... I see where you're going with this but it still allows me to[/color][/color]
              submit[color=blue][color=green]
              > > empty values. Thanks for the assistance!
              > >[/color]
              >
              > "submit empty values" ?? You are not submitting a form, you are simply
              > opening a new window with a URL parameter. The parameter happens to be a
              > variable scenario that mimics a form post. To verify that, put an
              > onsubmit="alert ('I am submitting')" on the form and see if you see it.
              > Using the above script, you won't. And as written, its not even
              > appending the variables, its simply opening a new window with the URL
              > set to the select value, and the name of the window being the same as
              > the "name" attribute of the option that was chosen at the time.
              >
              > Perhaps a little more explanation of what you are trying to do?
              > Submitting a search to google takes a little more than what you are doing.
              >
              > --
              > Randy
              > Chance Favors The Prepared Mind
              > comp.lang.javas cript FAQ - http://jibbering.com/faq/[/color]

              Sorry for any mistakes in posting to this thread (no professional news
              poster here but i do appreciate the help). The empty value I'm referring to
              is shown below. I want the ability to categorize options and not allow
              windows to be launched where the value is "". If you select "Select Service"
              below you'll see that a new window is launched to your default browser home
              page. Instead, I would like for the form to do nothing. I'm toying around
              with this but I greatly appreciate anyone's advice.

              <option value="" name="select">S elect Service</option> <!-- this has an
              empty value "" -->
              <option value="http://www.anydomain.c om/" name="anydomain ">Anywhere</option>
              <option value="http://www.whocares.co m/" name="whocares" >Who Cares</option>

              TIA - Rob


              Comment

              • Rob Wahmann

                #8
                Re: onselect open new window

                "Rob Wahmann" <rob@dotcomstud io.biz> wrote in message
                news:H_w2c.3137 8$PY.4729@newss vr26.news.prodi gy.com...[color=blue]
                > "Randy Webb" <hikksnotathome @aol.com> wrote in message
                > news:8sydnZBqLK xI0dfdRVn-iQ@comcast.com. ..[color=green]
                > > Rob Wahmann wrote:
                > >
                > > Top posting fixed - please read the FAQ with regards to top-posting,
                > > quoting and snipping.
                > >[color=darkred]
                > > >><script type="text/javascript">
                > > >> function launchIt(select ) {
                > > >> var option = select.options[select.selected Index];
                > > >> if (option != ''){
                > > >> window.open(opt ion.value,optio n.getAttribute( 'name'));
                > > >> }
                > > >> }
                > > >></script>
                > > > Hmm... I see where you're going with this but it still allows me to[/color][/color]
                > submit[color=green][color=darkred]
                > > > empty values. Thanks for the assistance!
                > > >[/color]
                > >
                > > "submit empty values" ?? You are not submitting a form, you are simply
                > > opening a new window with a URL parameter. The parameter happens to be a
                > > variable scenario that mimics a form post. To verify that, put an
                > > onsubmit="alert ('I am submitting')" on the form and see if you see it.
                > > Using the above script, you won't. And as written, its not even
                > > appending the variables, its simply opening a new window with the URL
                > > set to the select value, and the name of the window being the same as
                > > the "name" attribute of the option that was chosen at the time.
                > >
                > > Perhaps a little more explanation of what you are trying to do?
                > > Submitting a search to google takes a little more than what you are[/color][/color]
                doing.[color=blue][color=green]
                > >
                > > --
                > > Randy
                > > Chance Favors The Prepared Mind
                > > comp.lang.javas cript FAQ - http://jibbering.com/faq/[/color]
                >
                > Sorry for any mistakes in posting to this thread (no professional news
                > poster here but i do appreciate the help). The empty value I'm referring[/color]
                to[color=blue]
                > is shown below. I want the ability to categorize options and not allow
                > windows to be launched where the value is "". If you select "Select[/color]
                Service"[color=blue]
                > below you'll see that a new window is launched to your default browser[/color]
                home[color=blue]
                > page. Instead, I would like for the form to do nothing. I'm toying around
                > with this but I greatly appreciate anyone's advice.
                >
                > <option value="" name="select">S elect Service</option> <!-- this has an
                > empty value "" -->
                > <option value="http://www.anydomain.c om/"[/color]
                name="anydomain ">Anywhere</option>[color=blue]
                > <option value="http://www.whocares.co m/" name="whocares" >Who[/color]
                Cares</option>[color=blue]
                >
                > TIA - Rob[/color]

                function launchIt(select ) {
                var option = select.options[select.selected Index];
                if (option.getAttr ibute('name') != ''){
                window.open(opt ion.value,optio n.getAttribute( 'name'));
                }
                }

                Call me crazy but I believe I may have fixed this myself... The value or the
                name can empty and that's fine with me. The script above seems to work.
                Thanks again!

                Rob


                Comment

                • Randy Webb

                  #9
                  Re: onselect open new window

                  Rob Wahmann wrote:

                  <--snip-->
                  [color=blue]
                  > Call me crazy but I believe I may have fixed this myself... The value or the
                  > name can empty and that's fine with me. The script above seems to work.
                  > Thanks again![/color]

                  Glad you got it working.
                  --
                  Randy
                  Chance Favors The Prepared Mind
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  Working...