select length basics

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn Modersohn

    select length basics

    I've got

    <form name="form1>
    <select name="select1">
    <option value="null" selected>Select A Team</option>
    <option value="Cougars" >Cougars</option>
    <option value="Maverick s">Mavericks </option>
    <option value="Shortcut s">Shortcuts </option>
    </select>
    </form>

    If for example I wanted to document.write( the number of options in form
    1 using length property), how would I do that? I keep getting told that
    form1 has no properties when I try to get the length.

    Thanks for the help

  • Mick White

    #2
    Re: select length basics

    Shawn Modersohn wrote:
    [color=blue]
    > I've got
    >
    > <form name="form1>
    > <select name="select1">
    > <option value="null" selected>Select A Team</option>
    > <option value="Cougars" >Cougars</option>
    > <option value="Maverick s">Mavericks </option>
    > <option value="Shortcut s">Shortcuts </option>
    > </select>
    > </form>
    >
    > If for example I wanted to document.write( the number of options in form
    > 1 using length property), how would I do that? I keep getting told that
    > form1 has no properties when I try to get the length.
    >
    > Thanks for the help
    >[/color]

    The document.write( ) statement needs to be placed below the form on the
    page:
    ....</form>
    <p id="foo">
    <script type="text/javascript">
    document.write( document.form1. select1.length)
    </script>

    But I suspect you are unaware of the limitations of the use of the
    document's write method.

    Mick



    Comment

    • Shawn Modersohn

      #3
      Re: select length basics


      "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
      news:i9bIc.2964 6$yd5.15158@twi ster.nyroc.rr.c om...[color=blue]
      > Shawn Modersohn wrote:
      >[color=green]
      > > I've got
      > >
      > > <form name="form1>
      > > <select name="select1">
      > > <option value="null" selected>Select A Team</option>
      > > <option value="Cougars" >Cougars</option>
      > > <option value="Maverick s">Mavericks </option>
      > > <option value="Shortcut s">Shortcuts </option>
      > > </select>
      > > </form>
      > >
      > > If for example I wanted to document.write( the number of options in form
      > > 1 using length property), how would I do that? I keep getting told that
      > > form1 has no properties when I try to get the length.
      > >
      > > Thanks for the help
      > >[/color]
      >
      > The document.write( ) statement needs to be placed below the form on the
      > page:
      > ...</form>
      > <p id="foo">
      > <script type="text/javascript">
      > document.write( document.form1. select1.length)
      > </script>
      >
      > But I suspect you are unaware of the limitations of the use of the
      > document's write method.
      >
      > Mick
      >
      >[/color]

      Allright, maybe this will clarify

      /* A function that will navigate to a page based on an array */

      function gotoPage (){
      // Trying to figure out the length of the options , cant get it to work

      var arraylength = document.teamse lectionF.teamse lectionS.length

      // array section_I need to get the length of the options to auto update the
      length of the array

      var pagenav = new Array(arrayleng th)
      pagenav["null"] = "/localtest/null.html"
      pagenav["Cougars"]="/localtest/Cougars.html"
      pagenav["Mavericks"]="/localtest/Mavericks.html"
      pagenave["Shortcuts"]="/localtest/Shortcutss.html "

      // Section that actually naviagates to the page, takes the value of the
      option and uses it in the array

      var
      gotonum=documen t.teamselection F.teamselection S.options[document.teamse lectio
      nF.teamselectio nS.slectedIndex].value

      window.open(pag enav[gotonum])

      // debugging purposes just enters variable in form fields to check it works

      document.debug. uno.value=docum ent.teamselecti onF.teamselecti onS.selectedInd e
      x
      document.debug. dos.value=array length
      document.debug. dospointfive.va lue=gotonum
      document.debug. tres.value=page nav[gotonum]
      document.debug. quatro.value=ar raylength

      And for the html

      <form name="teamselec tionF">Please Select A team
      <select name="teamselec tionS" size="1">
      <option value="null" selected>Team_N ame</option>
      <option value="Cougars" >Cougars</option>
      <option value="Maverics ">Mavericks </option>
      <option value="Shortcut s">Shortcuts </option>
      </select>
      </form>


      And a section of html form that dumps the debug variable into form fields so
      I can check

      <form name="debug">
      selected Index <input type="text" value="" name="uno">
      ETC ETC ....

      This bit of code will be enable me to maintain the team list much more
      effectively, I wont have to update the length of the array each time I add a
      new team, all I will have to is add to the options and then the
      corresponding url in the array.


      Comment

      • Mick White

        #4
        Re: select length basics

        Shawn Modersohn wrote:
        [color=blue]
        >[color=green]
        >>
        >>But I suspect you are unaware of the limitations of the use of the
        >>document's write method.
        >>
        >>Mick
        >>[/color][/color]
        [color=blue]
        > Allright, maybe this will clarify
        >
        > /* A function that will navigate to a page based on an array */
        >
        > function gotoPage (){
        > // Trying to figure out the length of the options , cant get it to work
        >
        > var arraylength = document.teamse lectionF.teamse lectionS.length
        >
        > // array section_I need to get the length of the options to auto update the
        > length of the array
        >
        > var pagenav = new Array(arrayleng th)[/color]

        // I would avoid this construction:
        // var pagenav= new Array();
        [color=blue]
        > pagenav["null"] = "/localtest/null.html"
        > pagenav["Cougars"]="/localtest/Cougars.html"
        > pagenav["Mavericks"]="/localtest/Mavericks.html"
        > pagenave["Shortcuts"]="/localtest/Shortcutss.html "
        >
        > // Section that actually naviagates to the page, takes the value of the
        > option and uses it in the array
        >
        > var
        > gotonum=documen t.teamselection F.teamselection S.options[document.teamse lectio
        > nF.teamselectio nS.slectedIndex].value[/color]

        Should be "selectedIn dex"[color=blue]
        >
        > window.open(pag enav[gotonum])[/color]


        // whrn or how is this function called?

        Mick
        [color=blue]
        >
        > And for the html
        >
        > <form name="teamselec tionF">Please Select A team
        > <select name="teamselec tionS" size="1">
        > <option value="null" selected>Team_N ame</option>
        > <option value="Cougars" >Cougars</option>
        > <option value="Maverics ">Mavericks </option>
        > <option value="Shortcut s">Shortcuts </option>
        > </select>
        > </form>
        >[/color]
        [color=blue]
        >[/color]

        Comment

        Working...