A php and javascript question
Posted: Thu Sep 18, 2003 10:28 am
I'm writing a web page which contains 2 forms. THe first form has a listbox, how can I use onClick() to dynamically load the second form based on the listbox selection? My code is like this:
<form name="form1" method="post" action="">
<div align="center">
<select name="listbox1" onChange="display_index(document.form1.listbox1.value)">
<?php
do {
?>
<option value="<?php echo $row_document_type['dt_id']?>"<?php if (!(strcmp($row_document_type['dt_id'], $row_document_type['dt_description']))) {echo "SELECTED";}?> ><?php echo $row_document_type['dt_description']; ?></option>
<?php
mysql_select_db($database_localhost, $localhost);
$query_document_index_definitions = sprintf("SELECT * FROM t_documentindexdefinition WHERE dt_id = %s ORDER BY did_id ASC", $row_document_type['dt_id']);
$document_index_definitions = mysql_query($query_document_index_definitions, $localhost) or die(mysql_error());
$row_document_index_definitions = mysql_fetch_assoc($document_index_definitions);
$totalRows_document_index_definitions = mysql_num_rows($document_index_definitions);
$dt_id=$row_document_type['dt_id'];
echo "<script language='javascript'>";
echo "var document_index_definition$dt_id=new Array(";
do{
echo "'";
echo $row_document_index_definitions['did_description'];
echo "'";
echo ",";
}while ($row_document_index_definitions=mysql_fetch_assoc($document_index_definitions));
echo "'foo')";
echo "</script>";
?>
<?php
} while ($row_document_type = mysql_fetch_assoc($document_type));
$rows = mysql_num_rows($document_type);
if($rows > 0) {
mysql_data_seek($document_type, 0);
$row_document_type = mysql_fetch_assoc($document_type);
}
?>
</select>
</div>
</form>
How can I write the 2nd form's code to be dynamically show up using javascript?
Many thanks
<form name="form1" method="post" action="">
<div align="center">
<select name="listbox1" onChange="display_index(document.form1.listbox1.value)">
<?php
do {
?>
<option value="<?php echo $row_document_type['dt_id']?>"<?php if (!(strcmp($row_document_type['dt_id'], $row_document_type['dt_description']))) {echo "SELECTED";}?> ><?php echo $row_document_type['dt_description']; ?></option>
<?php
mysql_select_db($database_localhost, $localhost);
$query_document_index_definitions = sprintf("SELECT * FROM t_documentindexdefinition WHERE dt_id = %s ORDER BY did_id ASC", $row_document_type['dt_id']);
$document_index_definitions = mysql_query($query_document_index_definitions, $localhost) or die(mysql_error());
$row_document_index_definitions = mysql_fetch_assoc($document_index_definitions);
$totalRows_document_index_definitions = mysql_num_rows($document_index_definitions);
$dt_id=$row_document_type['dt_id'];
echo "<script language='javascript'>";
echo "var document_index_definition$dt_id=new Array(";
do{
echo "'";
echo $row_document_index_definitions['did_description'];
echo "'";
echo ",";
}while ($row_document_index_definitions=mysql_fetch_assoc($document_index_definitions));
echo "'foo')";
echo "</script>";
?>
<?php
} while ($row_document_type = mysql_fetch_assoc($document_type));
$rows = mysql_num_rows($document_type);
if($rows > 0) {
mysql_data_seek($document_type, 0);
$row_document_type = mysql_fetch_assoc($document_type);
}
?>
</select>
</div>
</form>
How can I write the 2nd form's code to be dynamically show up using javascript?
Many thanks