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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to transfer data from combo box to text box

Status
Not open for further replies.

peppe71

Technical User
Feb 6, 2002
27
IT
I have a page with one form and i need to transfer data from a combo box to a text box in the same pages.
The combo box receives data from a database.
 
Hi

Your combobox is called "combo" and text field is called "txtfield" in a page with one form in it. All "options" in the combo boax have a value set (from your recordset). Make sure your select code is like this:

Code:
<select name=&quot;combo&quot; onChange=&quot;settext(this.value)&quot;>

Then in the head section of the HTML code add this as a javascript function:

Code:
function settext(newval) { //v3.0
  document.forms[0].txtfield.value=newval;}
}

Sorted. You could try:

Code:
<select name=&quot;combo&quot; onChange=&quot;javascript:document.forms[0].txtfield.value=this.value;&quot;>

But it has never worked for me so I always stick to the two stage approach. This also gives me the opportunity to change as many fields as I like with one function call. Derren
[The only person in the world to like Word]
 
Here's how I did it. This is the line for the combo box:

<TD WIDTH=&quot;188&quot; HEIGHT=&quot;25&quot;><SELECT SIZE=&quot;1&quot; NAME=&quot;drpCust&quot; ONCHANGE=&quot;CustInfo()&quot;>

Here's the JavaScript function to fill the text box when a selection is made:

function CustInfo() {
document.frmIHeader.txtCustName.value = &quot;&quot;;
gcustno = document.frmIHeader.drpCust.value ;
document.frmIHeader.txtCustName.value = gcustno ;
}
 
your solution will not work with netscape4. change
document.frmIHeader.drpCust.value to
document.frmIHeader.drpCust.options[document.frmIHeader.drpCust.selectedIndex].value and that would fix it. [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top