#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    1
    Rep Power
    0

    Question PHP POST, JavaScript and <select>'s


    Hi all

    I need to POST the contents of a form select box, however, the page that the select box is on also requires the select box to be accessable via Javascript. So far, I have been able to get the POST working, and also the Javascript functions working, but I can't get them working at the same time.

    My problem is this line:
    <select class="libSelect" multiple size="4" name="elements[]">

    and later (in a Javascript block, obviously):
    function addInto(label, value, description) {
    document.frmLib.elements[].options[document.frmLib.elements[].options.length] = new Option(label, value, false, false);
    descriptions[document.frmLib.elements[].options.length] = description;
    }

    The problem (as I understand it) is that Javascript isn't happy about the name elements[] (thinking that it's part of a form object array I suppose), but for PHP to catch the POSTed value of "elements" correctly, it needs to be an array (ie. be named elements[])

    Any ideas, anyone?

    Thanks
    Chris
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    24
    Rep Power
    0
    OK, try declaring the select like this ...

    Code:
    <select id='elements' name="elements[]" class="libSelect" multiple size="4">
    And use the id in the javascript

    Code:
    descriptions[document.frmLib.elements.options.length] = description;
    HTH!
    Last edited by digitalAmit; August 14th, 2003 at 08:28 AM.

IMN logo majestic logo threadwatch logo seochat tools logo