Forums

This topic is locked

Autofill textbox??? HELP!!

Posted 23 Aug 2004 14:27:07
1
has voted
23 Aug 2004 14:27:07 Andy Smith posted:
Hi
I am looking for a way to fill in a textbox based on a dynamic dropdown list's value, but from another column in the record.

i.e. The database is setup like:

id | Operation | Details

The dropdown pulls all the operations out of the database.
I want the textbox to be autofilled with the details of the operation from the choice made in the dropdown.

So if someone selects, for example, 'my first operation' from 'form.operations' dropdown the form then fills the text box 'form.details' with the relevent details.

I know it's a longwinded explanation!

Any help would be greatly appreciated.

Andy

Replies

Replied 05 Nov 2004 01:02:44
05 Nov 2004 01:02:44 A. M. replied:
Andy--the way to pull this off is have the operations value from the database fill the drop down's visible values and have the details value fill the drop down's value portion. Then, with an onChange routine attached to the drop down box you can set the value of the input field to the value of the drop down box whenever a selection is made.
Here's a quick sample--this might, however, be a problem if your details are very lengthy--let me know if that's the case I can probably come up with something else.

<html>

<Script Language="JavaScript">
function fillText()
{
document.testForm.DetailText.value=document.testForm.OperationDropDown.value;
}
</Script>

<body>

<form name="testForm" id="testForm" action="">
Make Selection<br><br>
<select name="OperationDropDown" onChange="fillText()">
<option value="" selected="true">Select an operation</option>
<option value="detail 1">operation 1</option>
<option value="detail 2">operation 2</option>
<option value="detail 3">operation 3</option>
</select><br>
<input type="text" name="DetailText" id="DetailText" size="10">
</form>

</body>

</html>

Reply to this topic