selectbox

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

    selectbox

    Hello,

    When I have the next example, it shows me if item 2 is selected YES or NO

    <html>
    <script language="javas cript">
    function doit()
    {
    alert(document. forms["tst_frm"].elements["listbox"].options[2].selected)
    }
    </script>

    <body>
    <FORM id=tst_frm name=tst_frm action=javascri pt:doit() method=post>
    <SELECT multiple size=5 name=listbox>
    <OPTION value=1>1</OPTION>
    <OPTION value=2>2</OPTION>2
    <oPTION value=3>3</OPTION>
    <OPTION value=4>4</OPTION>
    <OPTION value=5>5</OPTION>
    </SELECT>

    <INPUT type=submit value="DOit" name=submit>

    </FORM>
    </body>
    </html>

    When I change then name field to a name with brackets (array)

    <SELECT multiple size=5 name=listbox[]> It won't work. How can the
    javascript work with the brackets in the name fields

    Many thanks in advance

    Richard



  • johkar

    #2
    Re: selectbox

    Your HTML syntax and JavaScript is invalid, wrong or both. Rather than
    rewrite the whole thing, why don't you tell us what you want the JavaScript
    to do and I or someone can show you how it is done. Are you just wanting to
    know which item or items are selected?

    John

    "Richard" <rjonker@hccnet .nl> wrote in message
    news:oPfqb.1585 64$Oz2.19514307 @amsnews03.chel lo.com...[color=blue]
    > Hello,
    >
    > When I have the next example, it shows me if item 2 is selected YES or NO
    >
    > <html>
    > <script language="javas cript">
    > function doit()
    > {
    > alert(document. forms["tst_frm"].elements["listbox"].options[2].selected)
    > }
    > </script>
    >
    > <body>
    > <FORM id=tst_frm name=tst_frm action=javascri pt:doit() method=post>
    > <SELECT multiple size=5 name=listbox>
    > <OPTION value=1>1</OPTION>
    > <OPTION value=2>2</OPTION>2
    > <oPTION value=3>3</OPTION>
    > <OPTION value=4>4</OPTION>
    > <OPTION value=5>5</OPTION>
    > </SELECT>
    >
    > <INPUT type=submit value="DOit" name=submit>
    >
    > </FORM>
    > </body>
    > </html>
    >
    > When I change then name field to a name with brackets (array)
    >
    > <SELECT multiple size=5 name=listbox[]> It won't work. How can the
    > javascript work with the brackets in the name fields
    >
    > Many thanks in advance
    >
    > Richard
    >
    >
    >[/color]


    Comment

    • richard

      #3
      Re: selectbox

      Wat is I want to do is create an listbox where you can select multiple
      items. The selection must be handedover to PHP as an array. The PHP code is
      running fine.
      Before the form is submitted, I have to check releatiosn to other field in
      the form. To simplify it, I made small example which has the same behaviour.

      Richard

      "Richard" <rjonker@hccnet .nl> wrote in message
      news:oPfqb.1585 64$Oz2.19514307 @amsnews03.chel lo.com...[color=blue]
      > Hello,
      >
      > When I have the next example, it shows me if item 2 is selected YES or NO
      >
      > <html>
      > <script language="javas cript">
      > function doit()
      > {
      > alert(document. forms["tst_frm"].elements["listbox"].options[2].selected)
      > }
      > </script>
      >
      > <body>
      > <FORM id=tst_frm name=tst_frm action=javascri pt:doit() method=post>
      > <SELECT multiple size=5 name=listbox>
      > <OPTION value=1>1</OPTION>
      > <OPTION value=2>2</OPTION>2
      > <oPTION value=3>3</OPTION>
      > <OPTION value=4>4</OPTION>
      > <OPTION value=5>5</OPTION>
      > </SELECT>
      >
      > <INPUT type=submit value="DOit" name=submit>
      >
      > </FORM>
      > </body>
      > </html>
      >
      > When I change then name field to a name with brackets (array)
      >
      > <SELECT multiple size=5 name=listbox[]> It won't work. How can the
      > javascript work with the brackets in the name fields
      >
      > Many thanks in advance
      >
      > Richard
      >
      >
      >[/color]


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: selectbox

        Richard wrote:
        [color=blue]
        > When I change then name field to a name with brackets (array)
        >
        > <SELECT multiple size=5 name=listbox[]> It won't work. How can the
        > javascript work with the brackets in the name fields[/color]

        <http://jibbering.com/faq/#FAQ4_25>


        PointedEars

        Comment

        • johkar

          #5
          Re: selectbox



          You should also get in the habit of quoting all your HTML attributes,
          matching case and so on...run it through a validator.

          John

          "richard" <rjonker@hccnet .nl> wrote in message
          news:3faa321f$0 $251$4d4ebb8e@r ead.news.nl.uu. net...[color=blue]
          > Wat is I want to do is create an listbox where you can select multiple
          > items. The selection must be handedover to PHP as an array. The PHP code[/color]
          is[color=blue]
          > running fine.
          > Before the form is submitted, I have to check releatiosn to other field in
          > the form. To simplify it, I made small example which has the same[/color]
          behaviour.[color=blue]
          >
          > Richard
          >
          > "Richard" <rjonker@hccnet .nl> wrote in message
          > news:oPfqb.1585 64$Oz2.19514307 @amsnews03.chel lo.com...[color=green]
          > > Hello,
          > >
          > > When I have the next example, it shows me if item 2 is selected YES or[/color][/color]
          NO[color=blue][color=green]
          > >
          > > <html>
          > > <script language="javas cript">
          > > function doit()
          > > {
          > >[/color][/color]
          alert(document. forms["tst_frm"].elements["listbox"].options[2].selected)[color=blue][color=green]
          > > }
          > > </script>
          > >
          > > <body>
          > > <FORM id=tst_frm name=tst_frm action=javascri pt:doit() method=post>
          > > <SELECT multiple size=5 name=listbox>
          > > <OPTION value=1>1</OPTION>
          > > <OPTION value=2>2</OPTION>2
          > > <oPTION value=3>3</OPTION>
          > > <OPTION value=4>4</OPTION>
          > > <OPTION value=5>5</OPTION>
          > > </SELECT>
          > >
          > > <INPUT type=submit value="DOit" name=submit>
          > >
          > > </FORM>
          > > </body>
          > > </html>
          > >
          > > When I change then name field to a name with brackets (array)
          > >
          > > <SELECT multiple size=5 name=listbox[]> It won't work. How can the
          > > javascript work with the brackets in the name fields
          > >
          > > Many thanks in advance
          > >
          > > Richard
          > >
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...