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

Text shown in <textarea> depending on option in <select> 1

Status
Not open for further replies.

MockY

Programmer
Jul 7, 2006
94
I have looked around and I am now officially giving up trying to code it myself from scratch. I'm very new to JavaScripting and need help.

I have a a simple option list (have removed all styling, values, and names:


<select>
<option>Who Are You?</option>
<option>John</option>
<option>Ryan</option>
<option>Sam</option>
</select>

Below it is a simple <textarea></textarea> box.

What I want to accomplish is depending on the selection, a predefined text will be entered in the textbox. In this case it's an e-mail form and the signature of the sender (the person in the option list) should be displayed automatically when the user selects his name.

How do I go about to do this?
 
Hi

A basic one, completely replaces the previous text :
Code:
<html>
<head>
<title></title>
<script type="text/javascript">
var sig=new Array()
sig['John']='Yours sincerely'
sig['Ryan']='Best wishes'
sig['Sam']='Kind regards'
function chSig(what)
{
  document.getElementById('ta').value=sig[what.options[what.selectedIndex].value]+',\n'+what.options[what.selectedIndex].value
}
</script>
</head>
<body>
<form action="">
<select onchange="chSig(this)">
<option>Who Are You?</option>
<option>John</option>
<option>Ryan</option>
<option>Sam</option>
</select>
<textarea id="ta"></textarea>
</form>
</body>
</html>

Feherke.
 
Works perfectly after a bit of tweaking (to fit my php scripts). Many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top