[ciapug] PHP/Java

Barry Von Ahsen ciapug@cialug.org
Mon, 12 Jan 2004 10:04:25 -0600


Dave J. Hala Jr. wrote:

> Here's a good one for monday morning:
> 
> I have a php script. The scripts reads some values from a mysql table
> and creates a listbox. Next to the listbox is an input field.
> What I'd like to do is have a small javascript that inserts a default
> value into the input field according to the option that was selected
> from the listbox.   The problem is that the values for the input field
> also come from a mysql table.
> 
> My question is, can the javascript use the data from a php array?

it can if you use PHP to write the javascript:
<script language="javascript">
<?
echo "jsArray = new Array(";
echo "\"".$inputvalue."\"";
$recordset->MoveNext();
while (!$recordset->EOF) {
	echo ", \"".$inputvalue."\"";
	$recordset->MoveNext();
}
echo ")"
// or echo "jsArray = new Array(\"".implode("\", \", $phpArray)."\")";
?>
document.form.inputbox.value = 
jsArray[document.form.listbox.selecteditem.value];
</script>

I'm sure my javascript is incorrect, but (hopefully) you get the idea

-barry