Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2007, 02:10 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default change content of textarea from select

Hi,

I have these sample strings
test1 = "This is sample string 1.";
test2 = "Sample string 2, present!";

And this:
<select name="blurbselect" onChange="setBlurb(this);">
  <option value="0"></option>
  <option value="1">Test1</option>
  <option value="2">Test2</option>
</select>

Now what I would like to do is that when I select Test1 from the select box, it will put the value of the string in a text area. Now I know that I could put the string value straight in the select, but my strings will be much longer, and I don't want to deal with it that way... Can someone suggest another option?

 
Old April 26th, 2007, 06:03 AM
Authorized User
 
Join Date: Oct 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
If I understand you right, this code will work for you.

------------------------------------------------------

<html>
<script>
test0 = "";
test1 = "test string 1";
test2 = "test string 2";
function setBlurb() {
var otionValue = document.form.blurbselect.value;
if (otionValue == "0") {
  document.form.textarea.value = test0;
} else if (otionValue == "1")
  document.form.textarea.value = test1;
  else if (otionValue == "2")
  document.form.textarea.value = test2;
};
</script>
<body>
<form name = 'form'>
<select name="blurbselect" onChange = "setBlurb();">
  <option value="0" ></option>
  <option value="1" >Test1</option>
  <option value="2" >Test2</option>
  <textarea name = "textarea" value = ""></textarea>
</select>
<form>
</body>

</html>
------------------------------------------------------

Guess switch operator will work faster than if-else-if for long list of options.

Best





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert textarea content into MySQL? a5xo3z1 Beginning PHP 14 October 2nd, 2008 01:47 PM
select either textarea or radiobutton pavani ASP.NET 2.0 Basics 1 March 21st, 2008 04:35 AM
Displaying textarea content to html table keithc Pro PHP 2 December 1st, 2006 03:12 AM
Display data in textarea with select statement Alex_forever MySQL 6 April 27th, 2004 06:05 PM
change TextArea in GUI from another class jermsv1 Java GUI 0 October 28th, 2003 02:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.