Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combo box with "Multiple" select option

    Ok. This what I have so far:
    when I select an option in the drop-down menu,
    the description is displayed in the textarea.
    The code below works fine but if I add the
    option "multiple" to my select statement then
    I need to change my select name to "one[]" so
    PHP will recognize it as an array.
    When I do this and change the name to "one[]" in
    my javascript, nothing will display in the
    textarea.

    Does anyone have an idea about how I might
    accomplish this?

    I just started programming Javascript
    about 3 weeks ago so any help would be
    greatly appreciated

    Thank you

    Harry


    <form name='forma'>

    <fieldset><legend $lft>$font4w<strong>Asset Management$ef</legend>
    <table background='5.jpg' width='100%'>
    <tr>
    <td $lft><select name='one' size='1' onChange='show_one()'>";
    $role="AM";
    get_it($role);
    echo "
    <select></td>
    <td $rgt>
    <textarea rows=2 cols=60 wrap='virtual' name='text_one'></textarea>
    </td>
    </tr>
    </table>
    </fieldset>";
    ?>

    <script language="javascript">
    var am=document.forma
    var am_desc=new Array()

    am_desc[0]="<?php echo $am_desc[0] ?>"
    am_desc[1]="<?php echo $am_desc[1] ?>"
    am_desc[2]="<?php echo $am_desc[2] ?>"
    am_desc[3]="<?php echo $am_desc[3] ?>"
    am_desc[4]="<?php echo $am_desc[4] ?>"

    am.text_one.value=am_desc[am.one.selectedIndex]

    function show_one()
    {
    am.text_one.value=am_desc[am.one.selectedIndex]
    }
    </script>
    </form>

    This is where I load my options from a database:
    The info in the select box is variable $rn
    and the description is variable $ad which I load
    into an array.

    <?php
    function get_it($role)
    {

    $am_desc=array();
    global $am_desc;

    $i=0;
    $qry="select * from ps_access where access_code='$role'";
    $result=mysql_query($qry);
    echo mysql_error();
    while(list($rn, $ad)=mysql_fetch_row($result))
    {
    if($role=="AM")
    $am_desc[$i]=$ad;

    echo "<option value='$rn'>$rn</option>";
    $i++;
    }
    mysql_close($link);
    }
    ?>
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bracket characters are swell in php but murder on (JS) dot syntax. Try:

    am.text_one.value=am_desc[am['one[]'].selectedIndex]

  • #3
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked perfectly. I really appreciate the help. You guys are great
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."


  •  

    Posting Permissions

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