/    Sign up×
Community /Pin to ProfileBookmark

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 [I]client[/I] dropdown that, on select, will make an ajax request that populates a container div with a related dropdown menu ([I]projects[/I]). 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:

[code=php]
<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>
[/code]

Ajax Request is made to ajaxcalling.php (select is populated to container div using innerHTML):

[code=php]
<?
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();
?>
[/code]

Form action contains:

[code=php]
$project = $_POST[‘details’];
$client = $_POST[‘category’];
[/code]

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

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@nthompsonauthorSep 24.2009 — 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:
[code=php]
echo "<option value='".$row['name']."'>".$row['name']."</option>"
[/code]


Works like a charm. Sorry to waste ya'll's time.
×

Success!

Help @nthompson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...