PDA

View Full Version : Preset chained selects



crazymao
05-26-2012, 03:58 AM
1) Script Title:
Chained Selects

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex16/chainedselects/index.htm

3) Describe problem:
So my question is, is there a way to preset the select options via html, not js. So like lets say im getting values from a database and i want the select statements to be already set to what the values were in the database, and preferably i dont want any messy js so is it possible to do with just php/html? Thanks guys

crazymao
05-27-2012, 07:51 AM
I found a solution, so if anyone for some reason ever wonders what I wondered, what I did was basically use php to add ", 1" to the end of the options i wanted to be preset, which basically makes them default, so then instead of including the script like you usually do in html, I did this:

<script type="text/javascript">
<?php

$myFile = "script.js";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize("script.js"));
fclose($fh);
$theData = str_replace("\"value\");", "\"value\", 1);", $theData);
echo $theData;

?>
</script>

I don't know if it makes sense how i described it but you can study the code and I'm sure you'll figure out what i did