I'm having a problem changing a select's options based on another select's option, below is the code that works:
dropdown2.innerHTML = "<?php echo($SQLFormElements->GetColumnAsOptions('SELECT `field2` FROM `table2` WHERE `field1` = \'8\' ')); ?>";
Explanation:
I have two database tables: table1 and table2. table1 has the field1. table2 has the fields field2 and field1. SQLFormElements is a php file that echoes out html elements based on mysql queries, in this case, options for a select element. dropdown1 contains field1 values. dropdown2 should display field2 values based on the value of field1, i.e. which is the selected item of dropdown1.
Anyways, the above code works fine, however i've hardcoded as opposed to getting the value, because when i do something like this:
var selectedItem = document.getElementById("ddField1");
dropdown2.innerHTML = "<?php echo($SQLFormElements->GetColumnAsOptions('SELECT `field2` FROM `table2` WHERE `field1` = \'" + selectedItem + "\' ')); ?>";
it does not work, any idea why!? i'm kinda stumped. Just a reminder, the first code snippet works.
I've tried the following:
- parsing the variable as an Integer (field1 in my table is an integer type)
- leaving out the quotes in the where clause
- leaving out the quotes but hard coding the value in the where clause works