I am probably making this more complicated than it need be and hope you guys can help clear my head.
In my database, I have a table with an enum field where most of the values contain have spaces in them. At the moment, I am trying to use a combination select, so that whenever someone select something in select one(which contains all the values of the enums, grabbed from the database by php), the select two dropdown will populate values related to what was selected in select one.
This is the script I am using to grab the select one values to populate select two:
$(function() {
$("#semester").change(function() {
$("#course").load("tester.php?semester=" + $("#semester").val());
});
});
The script i use to grab the enums:
$optionresult = mysql_result(mysql_query('SELECT column_type FROM information_schema.columns
WHERE table_name = "item" AND column_name = "'.$columnname.'"'),0);
$values = explode("','",substr($optionresult,6,-2));
for($i = 0; $i < count($values); $i++) {
echo '<option value="'.$values[$i].'">'.$values[$i].'</option>';
Something like Long-term and Spring2012 would get passed and posted, while something like Spring 2012 won’t.
Is there a way around this without having to type up each of the option values by hand, removing the space in the option value, and then adding it back in when I query it?
Try
encodeURIComponentwill take care of encoding the spaces in the querystring. It will change “First Semester” to “First%20Semester”.The server will decode this automatically– `$_GET[“semester”] will be “First Semester”;