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

    Join Date
    Dec 2000
    Posts
    23
    Rep Power
    0

    list (PHP) and javascript problem


    hi,

    what i learned from this discussion is that when we need to get
    value for the select html tag, we need to make our select name
    into something like me[], am i correct? but my problem is with this
    variable name, i have trouble manipulate them using javascript!




    <SELECT name="me" size=10>
    <OPTION value="0011">Jean Paul Gaultier</OPTION>
    <OPTION value="0009">Robbie Fowler</OPTION>
    <OPTION value="0005">Vialli</OPTION>
    <OPTION value="0001">Patrick Viera</OPTION>
    <OPTION value="0012">David Becham</OPTION>
    <OPTION value="0013">Lee Bowyer</OPTION>
    </SELECT>



    in javascript:
    var boxLength = document.projectform.me[].length;


    i got error. how?

    pls help...
    melv
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    In the case you post above, you shouldn't need to make the variable an array, since you don't have multiple selections enabled. (<SELECT MULTIPLE NAME="...), so you should just use

    var boxLength = document.projectform.me.length;


    If you want to be able to handle multiple selections, you would need something like:

    <SELECT MULTIPLE name="me[]" size=10>
    <OPTION value="0011">Jean Paul Gaultier</OPTION>
    <OPTION value="0009">Robbie Fowler</OPTION>
    <OPTION value="0005">Vialli</OPTION>
    <OPTION value="0001">Patrick Viera</OPTION>
    <OPTION value="0012">David Becham</OPTION>
    <OPTION value="0013">Lee Bowyer</OPTION>
    </SELECT>

    Then the multiple selections are available in an array, from me[0], to me[{number_of_selections}].
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    23
    Rep Power
    0

    Unhappy


    i tried using these code, but i got error message.

    document.projectform.me.length is not an object.


    below here is my code. IF i change the variable name to me
    instead of me[], i can display the boxLength properly. and
    this is my problem where in php, i need me[], but in javascript,
    i need me...so how?

    for the multiple select, since i will have 3 other select boxes which
    will hold multiple select, but here this is my main select and once
    i click them, they will assign to the one of the 3 select boxes, after
    that, i will need to pass into php code to process. I will have js
    do some pop / push type operation in the select boxes. and this
    is my problem if my variable will be in me[] instead of me.

    regards,
    melv


    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <SCRIPT LANGUAGE="JavaScript">

    function getme() {
    var boxLength = document.projectform.me.length;
    alert(boxLength);
    }

    </script>

    </head>

    <body bgcolor="#FFFFFF">
    <form name="projectform" method="get" action="#">
    <SELECT name="me[]" size=10 onChange="getme()">
    <OPTION value="0011">Jean Paul Gaultier</OPTION>
    <OPTION value="0009">Robbie Fowler</OPTION>
    <OPTION value="0005">Vialli</OPTION>
    <OPTION value="0001">Patrick Viera</OPTION>
    <OPTION value="0012">David Becham</OPTION>
    <OPTION value="0013">Lee Bowyer</OPTION>
    </SELECT>
    </form>
    </body>
    </html>
    Last edited by melvinfoo; May 8th, 2001 at 09:56 PM.
  6. #4
  7. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    I can't imagine why you need the name of that particual SELECT box to be "me[]". In this case, you are *never* passing more than one value with that input, so it doesn't need to be an array. But if you want to get the length of a SELECT MULTIPLE element with the name "me[]", you would access it this way:

    document.projectform["me[]"].length

    Otherwise Javascript tries to read an array-type name for a form element as another document object level or property:

    document.projectform.me.{undefined}.length

    HTH
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  8. #5
  9. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    23
    Rep Power
    0

    Talking


    oh yes! rycamor, thank you very very much!

    this is the answer i'm looking for ages...

    it solve my problem, the example code i gave is part of my complete
    code where i will have a total 4 list menu which will store
    the value passing from the code in the example. and the
    php will try to extract the value from the 4 menu.

    anyway, very thanks for the answer.

    melv

IMN logo majestic logo threadwatch logo seochat tools logo