php/javascript passing values to txtboxes
Posted: Mon Dec 19, 2011 9:38 pm
Hi everyone,
I need to select a companyname from a dropdownlist which in turn will populate the rest of the form fields. I'm not sure what I'm doing wrong.
and the dropdownlist code:
the dropdown list finds the companynames (or rather the funders) but nothing happens when the name is changed in the list. Can anyone offer any ideas? Thanks.
I need to select a companyname from a dropdownlist which in turn will populate the rest of the form fields. I'm not sure what I'm doing wrong.
Code: Select all
<script type="text/javascript">
var compInfoArray = new Array();
<?php
$funderquery = "SELECT * FROM icbcagencylookup ORDER BY FunderName";
$funderresult = mysql_query($funderquery) or die(mysql_error());
// build javascript array
while($funderrow=mysql_fetch_array($funderresult)){
echo 'compInfoArray['.$funderrow['FunderName'].'] = new Array();';
echo 'compInfoArray['.$funderrow['FunderName'].']["FunderTitle"] = "'.$funderrow['FunderTitle'].'";';
echo 'compInfoArray['.$funderrow['FunderName'].']["AgencyName"] = "'.$funderrow['AgencyName'].'";';
}
?>
function showname() {
var FunderName = document.form1.FunderName.value;
document.form1.FunderTitle.value = compInfoArray[FunderName]["FunderTitle"];
document.form1.FunderAgency.value = compInfoArray[FunderName]["AgencyName"];
}
window.onload=function() {
showname();
}
</script>
Code: Select all
<?php
$result=mysql_query("SELECT FunderName FROM icbcagencylookup order by FunderName ASC");
$options = '';
while ($row = mysql_fetch_assoc($result)) {
$selected = ($row['FunderName']==$FunderName) ? ' selected="selected"' : '';
$options .= "<option value=\"{$row['FunderName']}\"{$selected}>{$row['FunderName']}</option>\n";
}
?>
<select name="FunderName" id="FunderName" onchange="showname()" >
<option value="">< select > <?php echo $options ?></option>
</select>
the dropdown list finds the companynames (or rather the funders) but nothing happens when the name is changed in the list. Can anyone offer any ideas? Thanks.