Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How... OnChange of select box change value of multiple fields

Status
Not open for further replies.

sd0t1

IS-IT--Management
Mar 14, 2007
131
US
Hi guys, I have a problem and I think it's a rather easy answer, but I'm new to javascript so it's hard for me.

Here is what I'm asking.

I have a dynamic dropdown that's populated from a mysql database. Next to the dropdown there are 2 empty fields. I need to populate those 2 fields with the "id" and "description" of the item you selected from the dropdown before I submit the form. So I need it to refresh those fields or the whole form.
Right now, I can only make the actual item populate in a text box, and the ID and DESCRIPTION are empty.

Here is my code.
Thanks in Advance.

<script type="text/javascript">
function myName(){
var input = document.getElementById('userinput').value;
document.getElementById('oldname').innerHTML = input;
}
</script>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

Welcome to my site, <b id='oldname'>enter your name?</b></br>
<input type='text' id='oldname' />
<input type='text' id='id' value='<?php echo $row_test['id']; ?>'/>
<input type='text' id='description' value='<?php echo $row_test['description']; ?>'/>
<input type='button' value='Click'/>

<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<form id="form1" name="form1" method="post" action="" >
<label>
<select name="userinput" onchange="myName()">
<?php
do {
?>
<option value="<?php echo $row_test['user_name']?>"<?php if (!(strcmp($row_test['user_name'], $row_test['user_name']))) {echo "selected=\"selected\"";} ?>><?php echo $row_test['user_name']?></option>
<?php
} while ($row_test = mysql_fetch_assoc($test));
$rows = mysql_num_rows($test);
if($rows > 0) {
mysql_data_seek($test, 0);
$row_test = mysql_fetch_assoc($test);
}
?>
</select>
</label>
</form>
 
Can you post client-side code, not server-side code, as we have no idea of the structure of the data you're delivering (for all we know, you could be using delimited text in your options to denote ID, Description, etc).

Then point us in the direction of where the ID and Description are stored.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top