Basically what im trying to do is a much simpler version of the Chained Selectors that can be found here: http://www.zend.com/zend/tut/drop-down.php
i have a table with two fields. Template_name, and Template_text. The point of the script is to display the template_text automatically in a text box once the user chooses one of the templates in the select box (it lists the items in the Template_name field).
i have no other way of further explaining it than to show you the code i currently have. This is how far i've gotten. Perhaps one of you kind gentlemen could send me further? 😃
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script LANGUAGE="JavaScript">
function textValue(){
var templateInteger, templateString
templateInteger=document.templateForm.templateSelect.selectedIndex
templateString=document.templateForm.templateSelect.options[<?php $text = $option_. templateInteger . [2]; echo "$text"; ?>].text
document.templateForm.templateText.value = "I wish to speak to " + templateString +"!"
}
</script>
</head>
<body>
<?
// Database Connection Information
$db_host = "localhost";
$db_user = "*****";
$db_pass = "*****";
$db_name = "test";
// Connect to MySql
$conn = mysql_connect($db_host, $db_user, $db_pass)
or die(mysql_error());
$db_select = mysql_select_db($db_name, $conn)
or die(mysql_error());
// Sql query
$sql = "SELECT * FROM templates";
$result = mysql_query($sql)
or die(mysql_error());
// Start a counter to keep track of Options
$count = 1;
// Open Form and Select box
echo "
<form name=templateForm>
<B>Please Choose a Template:</B>
<br>
<select name=templateSelect onChange=textValue()>
<option selected>Choose a Template</option>
";
// Retrieve table info and place in arrays
while ($row = mysql_fetch_array($result)) {
$template_name = $row["template_name"];
$template_text = $row["template_text"];
${"option_$count"} = array (1 => "$template_name", "$template_text");
echo "
<option value=$template_text>$template_name</option>
";
$count++;
}
echo "
</select>
<input type=text name=templateText value=\"I wish to speak to Donald Duck!\" size=50 maxlength=75>
</form>
";
?>
</body>
</html>
Thanks for any help.
Mike