473,808 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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="hardc oded 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 2951
acoder
16,027 Recognized Expert Moderator MVP
If you have a textarea like this:
[html]<textarea id="textarea"> </textarea>[/html]then call a function onchange:
[html]<select onchange="chang eText(this.valu e);">
<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
148672
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 value="">Please make a selection</option> <option value="1">Choice 1</option> <option value="2">Choice 2</option> <option value="3">Choice 3</option>
19
6937
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 JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
13
6570
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
25014
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, that IE7 does not seem to offer any way to control the font size of a text input element.
3
5745
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 selection. Here what is I have done sofar, but for some reason it is not working: <form action=""> <select onchange="if (this.selectedIndex==1){document.getElementById.style.display='block'}else {document.getElementById.style.display='none'}; ...
4
20465
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 JS disables the select element correctly, but it does not re-enable it. Could someone please help with the right code. here is the Javascript code. function annconf() {
1
2423
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 displaying user names in listbox 2 based on selected of status in listbox. but its not displaying the emailid based on selection of usernames and when i click on search for users button its refreshs the page and shows the intial page also want the text box...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10631
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.