SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Newcastle
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Select box problem????

    Hi,

    I'm sorry if you've seen this message before but I wanted to re-post it so I could make it all clear.

    My problem is I have two select boxes I want to pass values between and I can happy do this:

    PHP Code:

    <select name="sel1" size="10" multiple>
    <?
    //build the content of the select box
    ?>
    <option><?=$data_not->docid?></option>
    </select>
    </td>
    <td align="center" valign="middle">
    <input type="button" value="-->" onClick="moveOptions(this.form['sel1'], this.form['sel2']);" /><br />
    <input type="button" value="<--" onClick="moveOptions(this.form['sel2'], this.form['sel1']);" />
    </td>
    <td>
    <?
    //build the content for the second box
    ?>
    <select name="sel2" MULTIPLE size="10">
    <?
    //put all data into options tabs
    <option><?=$data_in->docid?></option>
    </select>
    Which all works fine. I then go to pass the contents of sel2 into another PHP script and only the last value selected is passed. I want multiple values so I add [] to the select.
    <select name="sel2[]" MULTIPLE size="10">

    Now it passes the all the values but data can no long be transfered between boxes.

    The view the related thread to this:
    http://www.sitepoint.com/forums/showthread.php?t=183241

    Any help would be greatly appreciated.

    Craig

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of apologizing for double-posting: don't double post.

    Did you read the other replies?
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Newcastle
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that and it works but only one vlaue is still being passed though.
    I need the [] at the end of sub2 or sub1 to get more than one option though, don't I? and when I add it the select boxes will no long pass values.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're dealing with two different things. This:
    Code:
    <select name="sel2[]" MULTIPLE size="10">
    ...creates a PHP array you can loop through on the server; it does nothing unusual in the browser, though. If you name a form element this way, however, you can no longer use dot syntax (this.form.sel2[]) to refer to the drop-down, as square brackets are illegal characters in variable names. You must use this.form.elements['sel2[]']. The reference to the elements array is optional.

    <input type="button" value="-->" onClick="moveOptions(this.form.elements['sel1'], this.form.elements['sel2[]']);" /><br />
    <input type="button" value="<--" onClick="moveOptions(this.form.elements['sel2[]'], this.form.elements['sel1']);" />
    ::: certified wild guess :::

  5. #5
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Newcastle
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant!!!!!

    Sorry for being a bit of slow on the uptake there.

    Many thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •