473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Modify text in form based on selection (Option Select element)

I'm a javascript newbie - so although I can follow scripts and write simple ones, I get stuck when things don't work.

I'm trying to have a help section on my web-site where each question/FAQ will be on a drop-down box (Option Select). Beneath this I've set a textarea and I wanted this to be populated with the answer based on the user selection.

I've created an array of my answers in the header area and tried to get an ONCHANGE on the select box to fill the textarea box based on the array and the selected index. Nothing works. If I hard-code the result it does i.e. ONCHANGE textarea="hardcoded value" - but not when I try ONCHANGE textarea = array[selectedindex value].

Am I missing something obvious - or how can I do this.

Thanks.
Sep 4 '06 #1
1 2924
acoder
16,027 Expert Mod 8TB
If you have a textarea like this:
[html]<textarea id="textarea"></textarea>[/html]then call a function onchange:
[html]<select onchange="changeText(this.value);">
<option value="0">Test</option>
<option value="1">test 2</option>
<option value="2">test 3</option>
</select>[/html]and define the function and array like this:
Expand|Select|Wrap|Line Numbers
  1. var arr = ["Test 1","test 2","test 3\r\n"+"more"];
  2. function changeText(val) {
  3.     document.getElementById("textarea").value = arr[parseInt(val)];
  4. }
May 6 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
13
by: pkinville | last post by:
ok, this is gonna seem stupid, but it has been stumping me all afternoon. I have two fields on a HTML page. HTML looks like this... <html> <head> <title>New Page 3</title> </head> <body>
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
3
by: doc1355 | last post by:
Hi, I'm new to JavaScript. I'm trying to have a span on my form to sho some detail about the form element when the visitor is entering data. I need this to change based on the drop down menu...
4
by: cptuser | last post by:
Hi, I have an online form which has a select element, which I;m using very basic JS to enable and disable a select element based on the selection of another select element. For some reason, the...
1
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.