select listbox that does a form submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Novotny

    #1

    select listbox that does a form submit


    Hi,

    I'm trying to create a listbox using <select> HTML tags that can do
    a form submit when an option in the list is selected. So far this works,


    function MySelectSubmit( ) {
    document.myform .submit();
    }

    with HTML:

    <form name="myform" method="post" action="myselec t">

    <select name='myselect' size='1' onChange='MySel ectSubmit()'>
    <option value='hi' selected='selec ted' >Hello</option>
    <option value='bye'>Goo dbye</option>
    </select>

    </form>

    Now my question is how can I make the javascript method general enough
    so I can pass in any form so that it does not have to refere to "myform"
    in the body. I tried the following but it doesn't work:

    function MySelectSeubmit ( aform ) {
    document.aform. submit();
    }

    Thanks, Jason



  • Michael Winter

    #2
    Re: select listbox that does a form submit

    On Mon, 19 Jan 2004 10:23:41 -0800, Jason Novotny <novotny@aei.mp g.de>
    wrote:
    [color=blue]
    > I'm trying to create a listbox using <select> HTML tags that can do
    > a form submit when an option in the list is selected. So far this works,[/color]

    I don't quite know the wisdom of that; it depends on the content of the
    SELECT box and how clear it is that the selection made is final. What if
    the user makes a mistake?
    [color=blue]
    > Now my question is how can I make the javascript method general enough
    > so I can pass in any form so that it does not have to refere to "myform"
    > in the body.[/color]

    It depends what you are passing to the method. If it is a reference to the
    form object, you can do:

    function mySubmit( myForm ) {
    myForm.submit() ;
    }

    If you are passing the name of the form, you'll need to do:

    function mySubmit( myForm ) {
    document.forms[ myForm ].submit();
    }

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Lee

      #3
      Re: select listbox that does a form submit

      Jason Novotny said:[color=blue]
      >
      >
      >Hi,
      >
      > I'm trying to create a listbox using <select> HTML tags that can do
      >a form submit when an option in the list is selected. So far this works,
      >
      >
      > function MySelectSubmit( ) {
      > document.myform .submit();
      > }
      >
      >with HTML:
      >
      ><form name="myform" method="post" action="myselec t">
      >
      ><select name='myselect' size='1' onChange='MySel ectSubmit()'>
      > <option value='hi' selected='selec ted' >Hello</option>
      > <option value='bye'>Goo dbye</option>
      ></select>
      >
      ></form>
      >
      >Now my question is how can I make the javascript method general enough
      >so I can pass in any form so that it does not have to refere to "myform"
      >in the body. I tried the following but it doesn't work:
      >
      >function MySelectSeubmit ( aform ) {
      > document.aform. submit();
      >}[/color]

      Only the first component of a dot-notation identifier may be a
      variable. If aform is a variable containing the name of the
      form, you can use:

      document.forms[aform].submit();

      but it would be even simpler to pass a reference to the form,
      instead of its name. You would pass it with:

      onChange='MySel ectSubmit(this. form)'

      Note that "this.form" is exactly what you would use. Don't
      replace any part of it with your own names. It's a built-in
      reference to the form that contains the form element that the
      event handler belongs to.

      Then your function would look like:

      function MySelectSubmit( aform ) {
      aform.submit();
      }

      Since "aform" is now a reference directly to the form, you
      don't need to qualify it with the document reference.

      Comment

      Working...