p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   change content of textarea from select (http://p2p.wrox.com/showthread.php?t=56488)

darkhalf April 10th, 2007 02:10 PM

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?


annienell April 26th, 2007 06:03 AM

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


All times are GMT -4. The time now is 02:57 AM.

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