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!

assign value to textarea when select option onchange w/o submit form ?

Status
Not open for further replies.

stonehead

Technical User
May 2, 2007
58
US
Hi,

I have a textarea for users to type response message in and a select option for canned responses in case users want to use them. What I want is to insert some value into the textarea when the select "onchange" fires. I got the value populated fine into the select listbox but I can't not get anything written into the textarea (without submit the form) on the onchange event. Thanks in advance for your help.
Below is the code I currently have:

<select id="optCResponse" name="optCResponse" onchange = "SelectCResponse(this)";>
<Option value="" selected>Select a Canned Response</option>

<%

While Not rs.EOF

%>

<option name="optCResponse" value="<%= rs("Description")%>"><b> <%= rs("CResponseID")%></b>&nbsp <%= left(rs("Description"), 20)%>...</option>

<%
RS.MoveNext
WEnd

rs.Close
objConn.Close
Set rs = Nothing
Set objConn = Nothing
%>
</select>

<tr>
<td class=font><p>&nbsp;<b>Reply Message</b>

<textarea name="txtRespMessage" size=8000 rows="8" cols="40" wrap="VIRTUAL" scrolling="yes" value="<%= request.form("txtRespMessage")%>"></textarea>


<script type="text/javascript">


function SelectCResponse(theForm)
{
theForm.txtRespMessage.value = "write something here"
}
 
I don't want the form to be submitted. That's part of my real code. At the begining I have

<table border=0 cellpadding=2 cellspacing=0 width=100%>
<form name="ResponseForm" method="post" action="ResponseConfirm.asp" onSubmit="return frmAdd_Validator(this)">


Everything works fine exept I don't get anything written to the textarea on onchange event. Does the form have to be submitted to make that happen ?

thanks,
 
No it does not... Make sure that frmAdd_Validator is returning false if you do not want your form to be submitted.

Also, change this:

Code:
onchange = "SelectCResponse(this)";

to this:

Code:
onchange = "SelectCResponse(this[!].form[/!])";

as you were passing a reference to the select element, not to the form itself.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
>function SelectCResponse(theForm)
> {
> theForm.txtRespMessage.value = "write something here"
> }

[tt]
function SelectCResponse(obj)
{
obj.[blue]form.[/blue]txtRespMessage.value = "write something here[green]; the select-one value can be reference via obj.value and its text can be reference via obj.text here[/green]"
}
[/tt]
I change the name thisForm because it is not the form reference yet, so it is misleading to yourself.
 
It works! Thank you all so much for your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top