php and select and hidden value onchange
Posted: Sun May 10, 2009 9:56 pm
I am trying to do onchange from drop down menus.
The values are all coming from mysql on teh fly.
I am trying to build a frontend to mysql that the user can pick what they want to display from the query they build drop down menus.
Here is the basic code I Use to make the drop down.
');
The Menu are all
I can't figure out how I am to add onchange to call a php function to continue.
I want to update the menus (16 of them) so it will update all the menus and make sure there is no invalid options available in the 16 drop down menus
would love it to use AJAX but I have spent 2 weeks trying to figure out to do that.
I trying to figure out cookies.
and input hidden items.
Any help would be great I can't sleep well I dream of ways to make it work.posting.php?mode=post&f=1&sid=cd27c5272 ... bddade97e1#
Anyone can help it would make my day.posting.php?mode=post&f=1&sid=cd27c5272 ... bddade97e1#
I have most of the code written in php there is some javascript to deal with the activewidget. I almost using AmCharts to display and the data collected.
I tried this but quoting is wrong in the php code
Someone please help.
Thanks
Steven
The values are all coming from mysql on teh fly.
I am trying to build a frontend to mysql that the user can pick what they want to display from the query they build drop down menus.
Here is the basic code I Use to make the drop down.
Code: Select all
function GenericDropDown($title, $postname, $AddThese)
{
echo "\r\n" . $title . "\r\n";
$dropdownstring = "<select name='$postname' id='" . $postname . "'>"; //"<select name='Local_Name[]' multiple='multiple'>";
foreach ($AddThese as $item)
{
if (isset($_POST[$postname]) && ( $item == $_POST[$postname] )) // Is not a Array single drop down menu
$dropdownstring .= "\r\n\t<option value=\"" . $item . "\" selected='selected'>" . $item . "</option>";
else
$dropdownstring .= "\r\n\t<option value=\"" . $item . "\">" . $item . "</option>";
}
$dropdownstring .= "\r\n</select>\r\n";
echo $dropdownstring;
}
function SingleDropDown($title, $postname, $fieldName, $dataset)
{
echo "\r\n" . $title . "\r\n";
$dropdownstring = "<select name='$postname' id='" . $postname . "'>"; //"<select name='Local_Name[]' multiple='multiple'>";
//$dropdownstring = "<select name='$postname' >"; //"<select name='Local_Name[]' multiple='multiple'>";
$dropdownstring .= "\r\n\t<option value=\"NONE\">--- All ---</option>";
while($row = mysql_fetch_assoc($dataset))
{
//print_r ("row " . $row . "<br>");
if (isset($_POST[$postname]) && ( $row[$fieldName] == $_POST[$postname] )) // Is not a Array single drop down menu
{
$dropdownstring .= "\r\n\t<option value=\"{$row[$fieldName]}\" selected='selected'>{$row[$fieldName]}</option>";
}
else
{
$dropdownstring .= "\r\n\t<option value=\"{$row[$fieldName]}\">{$row[$fieldName]}</option>";
}
}
$dropdownstring .= "\r\n</select>\r\n";
echo $dropdownstring;
}
$query4 = "SELECT DISTINCT machine_name FROM SATA ORDER BY machine_name DESC";
$dataset4 = @mysql_query($query4, $inventario);
SingleDropDown("Machine Name:" , "Machine_Name", "machine_name" , $dataset4);
print_r('</td>
<td class="DataLeft" height="25">
The Menu are all
I can't figure out how I am to add onchange to call a php function to continue.
I want to update the menus (16 of them) so it will update all the menus and make sure there is no invalid options available in the 16 drop down menus
would love it to use AJAX but I have spent 2 weeks trying to figure out to do that.
I trying to figure out cookies.
and input hidden items.
Any help would be great I can't sleep well I dream of ways to make it work.posting.php?mode=post&f=1&sid=cd27c5272 ... bddade97e1#
Anyone can help it would make my day.posting.php?mode=post&f=1&sid=cd27c5272 ... bddade97e1#
I have most of the code written in php there is some javascript to deal with the activewidget. I almost using AmCharts to display and the data collected.
I tried this but quoting is wrong in the php code
Code: Select all
$dropdownstring = "<select name='$postname' id='" . $postname . "' onchange="storeVal(this,'hiddenVal');>";
<script>
function storeVal(selectObj,id)
{
var hiddenObj = document.getElementById(id);
var optionArr = selectObj.getElementsByTagName("option");
if (selectObj.value == "default") return false;
for (i=1; i<=optionArr.length; i++)
{
if (selectObj.value == optionArr[i].value)
{
hiddenObj.value = valPairs[selectObj.value];
return alert('The hidden value is "'+hiddenObj.value+'"');
}
}
}
</script>
Thanks
Steven