View Single Post
  #1 (permalink)  
Old Nov 24th, 2005, 13:39
stevoh stevoh is offline
New Member
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Multiple Drop Down

Hello I have created a small php file which is going to be a module in my mambo driven intranet site. The problem I am having is having one of the drop downs do two things on 'onChange'
1) Change the href of the page/content
2) Update the second drop down based on the selection chosen
here is me code...
Code: Select all
<html>
<script language="javascript" type="text/javascript">
function change() {
document.location.href='index.php?option=content&task=category&sectionid=6&id=' + document.form1.options[selectedIndex].value
+ '&Itemid= '+document.form1.options[selectedIndex].id+'';
}
</script>
<body>
<?PHP
$db = mysql_connect();
mysql_select_db("mambo",$db);
$query = 'SELECT id, componentid, name FROM `mos_menu` WHERE parent =53';
$areas = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($areas);
?>
<form name="form1" id="form1" method="post" action="">
<select name="area" id="area" onchange="javascript:document.form1.submit();">
<option value="" selected="selected">Select an area...</option>
<?php
for ($i=0; $i < $num_rows; $i++)
{
$row_area = mysql_fetch_array($areas);
?>
<option value="<?php echo $row_area['componentid'] ?>" id="<?php echo $row_area['id'] ?>"><?php echo $row_area['name'] ?></option>
<?PHP
}//for
?>
</select>
</form>
<br><br>
<select onchange="document.location.href='index.php?option=content&task=view&id=' + this.options[selectedIndex].value + ' &Itemid= '+this.options[selectedIndex].id+'';">
<option selected="selected">Select a document...</option>
<?PHP
// Quick hack to swap around the id and component id for href
$doc_area = $_POST['area'];
$query_area = "SELECT id, name FROM `mos_menu` WHERE parent =53 AND componentid='$doc_area'";
$id_change = mysql_query($query_area) or die(mysql_error());
$row = mysql_fetch_assoc($id_change);
$cat_id = $row['id'];
// Retrieve area id and find all documents related to the selected area
$query_doc = "SELECT id, title, catid FROM `mos_content` WHERE catid ='$doc_area'";
$area_docs = mysql_query($query_doc) or die(mysql_error());
$doc_rows = mysql_num_rows($area_docs);
for ($i=0; $i < $doc_rows; $i++)
{
$row_docs = mysql_fetch_array($area_docs);
?>
<option value="<?php echo $row_docs['id'] ?>" id="<?php echo "$cat_id" ?>"><?php echo $row_docs['title'] ?></option>
<?PHP
}//for
?>
</select>
<?PHP
$temp = $_POST['area'];
if ($temp != "")
{
echo "<script language='javascript' type='text/javascript'>change();</script>";
}
?>
</body>
</html>
As you can see, i know onchange cant do two things so I have written a Javascript function which recognizes when something has been posted and it needs to change the href...problem only is it doesnt work!!
Any help/input would be much appreciated.
Thanks Guys/Gals

Last edited by benbacardi; Nov 24th, 2005 at 16:19. Reason: Code Tags
Reply With Quote