www.webdeveloper.com
Results 1 to 2 of 2

Thread: Dependent Dropdown Incomplete Data

  1. #1
    Join Date
    Apr 2009
    Posts
    14

    Dependent Dropdown Incomplete Data

    Hullo!

    I have a set of dependent dropdown boxes and a very confusing anomaly with my dropdown data. I have a client dropdown that, on select, will make an ajax request that populates a container div with a related dropdown menu (projects). The whole thing works great until the user data from the form is processed. For some reason the value of my project dropdown is always cut off at the first whitespace. This doesn't happen for any of the other data (which also contains whitespace). For example the value, 'Web Project', is submitted as 'Web'. The client dropdown, however, will submit the data correctly, whitespace or not.

    Client dropdown and subsequent div to load the dependent:
    PHP Code:
    <select name="category" onChange="CategoryGrab('ajaxcalling.php?idCat='+this.value);" class="validate[required]">                <option>---</option>
    <?
        
    require "connect.php";// connection to database 
        
    $q=mysql_query("SELECT company FROM clients");
        while(
    $n=mysql_fetch_array($q)){
             echo 
    "<option value='{$n['company']}'>{$n['company']}</option>";
        }
    ?>
    </select>
    <div style="height:30px;" id="details"></div>
    Ajax Request is made to ajaxcalling.php (select is populated to container div using innerHTML):
    PHP Code:
    <?
    include("connect.php");
    $ID=$_REQUEST['idCat'];
    echo 
    '<select name="details" width="100">';
    $result mysql_query("SELECT * FROM projects WHERE client='$ID'");
        while(
    $row mysql_fetch_array($result))
        {
         echo 
    "<option value=".$row['name'].">".$row['name']."</option>";
        }
    echo 
    '</select>';
    mysql_close();
    ?>
    Form action contains:
    PHP Code:
    $project $_POST['details'];
    $client $_POST['category']; 
    I don't get it, client and project dropdowns both populate correctly, both have identical processing, yet the project gets cut off at the first whitespace. Any ideas?

    Thanks a ton!
    Nick

  2. #2
    Join Date
    Apr 2009
    Posts
    14
    Okay, really stupid mistake on my part. I forgot to add an extra set of quotes around the OPTION value.

    In ajaxcalling.php it should be:
    PHP Code:
    echo "<option value='".$row['name']."'>".$row['name']."</option>" 
    Works like a charm. Sorry to waste ya'll's time.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles