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

Drop down to populate text box

Status
Not open for further replies.

NEveritt

MIS
Dec 30, 2002
25
0
0
GB
Using ASP & SQL:

I have a table with:

IDColumn, CostType , CostValue

I have a populated drop down list that contains just the costtype.

When someone selects one of the items it needs to put the costs into the text field.

Im expecting its using the Onchange on the drop down list.

What I dont know how to do is get the connected cost value into the text box.

All help needed here, as I do not really have a clue what to do, but I know I do not want to refresh the page.
 
Use the pair to set up options, then you won't need to search the table.
[tt] <option value="<%=rs("CostValue")%>"><%=rs("CostType")%></option>
[/tt]
 
so how do i then get the value into the text box?

this is all bearing in mind that I need to then at the end, when the form has been completed insert values into a table, the only value one of the 3 values i listed that needs to go back into the databse is the IDColumn
 
Simply this for the onchange handler. Let's say the text box is in the same form and with name "textbox"
[tt] <select name="selectname" onchange="this.form.textbox.value=this.value">[/tt]
 
that works, but i will need the ID to send back to the database, so how do i get around that?
 
[1] select's value is "sent" back to server when submit. If you think only text/hidden element can be sent back, it is a misunderstanding.
[2] You can make a comma-delimited string for the value of option(s). (Or the comma here means any symbolic string of a unique character unlikely to appear in the id and name.)
[tt]<option value="<%=rs("CostValue") & "," & rs("IDColumn")%>"><%=rs("CostType")%></option>[/tt]
[3] Then onchange parse and distribute the information to the two text/hidden boxes.
[tt] <select name="selectname" onchange="this.form.textbox0.value=this.value.split(/,/)[0]; this.form.textbox1.value=this.value.split(/,/)[1];">[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top