Forums

ASP

This topic is locked

Populate form field from dynamic list

Posted 06 Sep 2004 04:11:15
1
has voted
06 Sep 2004 04:11:15 Charles Knight posted:
Hi all
I need to populate a form text box with items from a dynamic dropdown list.

What I can't figure out is once I select the item from the dynamic dropdown list, how do I get the page to auto-refresh to show the choice I made appear in the text box.

Thanks for any help
CK

Replies

Replied 06 Sep 2004 05:21:02
06 Sep 2004 05:21:02 Charles Knight replied:
Realise its an OnChange function I need now.

Have looked at all sorts of examples and forums and all seem way too complicated.

I want simply to take one item from a dynamic dropdown list and automatically put it in a form text box.

ck
Replied 07 Sep 2004 14:29:45
07 Sep 2004 14:29:45 Andrew Watson replied:
do this in javascript....

select box on change event...fires a function that...

a) gets the selected value of the select list
b) appends it to the text box

something like....

function appendValueToTextArea()
var ValueToAppend = document.getElementByID("selectlist".value
varCurrentTextareaValue = Document.getElementByID("textbox".value

{now set it}

document.getELementByID("textbox".value = varCurrentTextareaValue + chr(13) + ValueToAppend ....

dont copy and paste that code as it wont work its just the idea that you should follow...this will be quite simple and should take only 3 or four lines of code..

:: Son, im Thirty.... ::
Replied 08 Sep 2004 01:46:00
08 Sep 2004 01:46:00 Charles Knight replied:
Thanks Leed
For you this maybe easy for me, well what can I say.
I've searched and read most of the post on this forum to do with Onchange and I've search most of Google against on all the Onchange subjects I can think of.

All I want is what I posted above, to take one value from a dynamic dropdown box and automatically put in a text box....
Replied 14 Sep 2004 09:05:12
14 Sep 2004 09:05:12 Charles Knight replied:
Just in case anyone wants the full answer, copy this into any form, add your db connection, etc etc and off you go, works a treat.

<script language="JavaScript"><!--
function onChange() {
var Current =
document.Form.dynamic_dropdown.selectedIndex;
document.Form.text_box.value =
document.Form.dynamic_dropdown.options[Current].value;
}
//--></script>

<form
name="Form" id="Form"
onSubmit="return false;"
>
<select
name="dynamic_dropdown"
onChange="onChange()"
>
<%
While (NOT rsdb.EOF)
%>
<option value="<%=(rsDb.Fields.Item("value".Value)%>"><%=(rsMachines.Fields.Item("Name".Value)%></option>
<%
rsMachines.MoveNext()
Wend
If (rsdb.CursorType > 0) Then
rsdb.MoveFirst
Else
rsdb.Requery
End If
%>
</select>
<br>
<br>

Current Value:
<input
name="text_box"
type="text"
value=""
>
</form>
Replied 14 Sep 2004 09:05:25
14 Sep 2004 09:05:25 Charles Knight replied:
Just in case anyone wants the full answer, copy this into any form, add your db connection, etc etc and off you go, works a treat.

<script language="JavaScript"><!--
function onChange() {
var Current =
document.Form.dynamic_dropdown.selectedIndex;
document.Form.text_box.value =
document.Form.dynamic_dropdown.options[Current].value;
}
//--></script>

<form
name="Form" id="Form"
onSubmit="return false;"
>
<select
name="dynamic_dropdown"
onChange="onChange()"
>
<%
While (NOT rsdb.EOF)
%>
<option value="<%=(rsDb.Fields.Item("value".Value)%>"><%=(rsMachines.Fields.Item("Name".Value)%></option>
<%
rsMachines.MoveNext()
Wend
If (rsdb.CursorType > 0) Then
rsdb.MoveFirst
Else
rsdb.Requery
End If
%>
</select>
<br>
<br>

Current Value:
<input
name="text_box"
type="text"
value=""
>
</form>

Reply to this topic