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

Put dropdown value into input text box 1

Status
Not open for further replies.

hamish75

Technical User
Dec 18, 2009
39
GB
i need to populate an input with a value that is taken from a dropdown menu. the dropdown menu is populated by a look-up table.

here is the dropdown menu:
Code:
<select name="Edit" id="Edit">
<%
sql = "SELECT * FROM [Sales] ORDER BY [Sales Code] ASC;"
Set rs = obj_CN.Execute(sql, adBoolean)

' Build the menu
While Not rs.EOF

strSalesID = rs("Sales_ID")
strSales = rs("Sales code")
strSalesDescription = rs("Sales Description")
strOption = "<option value=""" & strSalesID & """#Selected#>" & strSales & " - " & strSalesDescription & "</option>"
Response.Write vbtab & strOption & vbcrlf
rs.MoveNext
Wend
%>
</select>

the input box is straight foward:

Code:
<input name="EditSalesDescription" id="EditSalesDescription" type="text" size="10" value="" >

any help on this would be great.

thanks.


Ah dinnae ken...
 
can you provide us with the following :

1, The output HTML source of the page in question
2, How you want this function to be triggered, e.g. is there a button or just when a value is changed in the dropdown ?

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
1, not sure what the output source is? the dropdown menu and input box are part of a form that posts to another page where an SQL statement updates an SQL database.

2, the function needs to change when the value is changed in the dropdown.

thank you.

Ah dinnae ken...
 
It looks like you want the description from the Pulldown in the input field...
a) Put the description in de value from the <OPTION> (instead id)?

b) look at this:
Code:
<html>
<head>
<script language="javascript">

    function FillText() {
        var selObj = document.getElementById('select1');
        var txtObj = document.getElementById('text1');

        var selIndex = selObj.selectedIndex;
        var txt = txtObj.value;
        txtObj.value = txt + selObj.options[selIndex].text;

        
        
     }
    
</script>

</head>
<body>

<form id=frm1 name=frm1>
<select name="select1" id="select1" onchange="FillText();">
<option value="AA">AA</option>
<option value="BB">BB</option>
<option value="CC">CC</option>
<option value="DD">DD</option>
</select>
<input type="text" id="text1" name="text1" />
</form>



</body>
</html>
 
ah that works perfect! thank you.

i made one wee tweak to change the value passed just to suit what i needed:

Code:
To:
selObj.options[selIndex].[COLOR=red]value[/color];

many thanks


Ah dinnae ken...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top