Hi all,
I'm working on a javascript function using PHP to populate a dropdown list from a database. I'm sure that my problem is actually in my javascript syntax, so I am posting in this forum.
The key values I'm talking about appear in my database as follows:
When I attempt to add these values to my option list by doing the following:
When I go to run the page, I can see the javascript error:
Obviously I should be escaping the apostrophe. The problem is, escaping an apostrophe looks pretty lousy in a production form.
Is there any other way of writing the new Option () function?
Thanks in advance.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Cheers!
Laura
I'm working on a javascript function using PHP to populate a dropdown list from a database. I'm sure that my problem is actually in my javascript syntax, so I am posting in this forum.
The key values I'm talking about appear in my database as follows:
Code:
+----+-------------------+
| ID | PLACE_NAME |
+----+-------------------+
| 9 | Laura\'s Place |
+----+-------------------+
Code:
$sql = "SELECT * FROM PLACE WHERE CITY_ID = $city";
$results = mysql_query($sql,$connection)
or die("SQL Error on query: " . $sql . "<br>" . mysql_error());
while ($row = mysql_fetch_array($results)){
$place_id = $row['ID'];
$place = stripslashes($row['PLACE_NAME']);
$display_block .= "document.forms['places_form'].elements['places'].options[$ctr] = new Option('$place',$place_id);\n";
$ctr++;
}
return $display_block;
// returns $display_block to function that writes the javascript
When I go to run the page, I can see the javascript error:
Code:
Error: missing ) after argument list
Source Code: document.forms['places_form'].elements['places'].options[1] = new Option('Laura's Place',9);
//the error pointer is pointing at the 's' following the apostrophe
Obviously I should be escaping the apostrophe. The problem is, escaping an apostrophe looks pretty lousy in a production form.
Is there any other way of writing the new Option () function?
Thanks in advance.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Cheers!
Laura