473,407 Members | 2,312 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,407 software developers and data experts.

Changing the value of texfiled using onChange?

Hi.
I need to get simple script working.
I have many select object.
When I select a different option, I would like to change the value of
corresponding text input field.
How can I do this using javascript?

Here is what I have so far.

<SELECT NAME=\"%s\" onChange=\"fill_desc(this.form, $name, $field_name)>

<script language="javascript">
<!-- Hide me please!
function fill_desc(form, name, field_name) {
var myindex=form.name.selectedIndex
if(form.name.options[myindex].value != "0") {
form.field_name.value = form.name.options[myindex].value;
}
}
//-->

Thanks for your help.
Jul 20 '05 #1
1 2999
Lee
Young-Soo Roh said:

Hi.
I need to get simple script working.
I have many select object.
When I select a different option, I would like to change the value of
corresponding text input field.
How can I do this using javascript?

Here is what I have so far.

<SELECT NAME=\"%s\" onChange=\"fill_desc(this.form, $name, $field_name)>
You seem to be missing a closing \" in that line, but it looks like
you've only shown part of it, so that's probably not really a problem.
<script language="javascript">
<!-- Hide me please!
function fill_desc(form, name, field_name) {
var myindex=form.name.selectedIndex
if(form.name.options[myindex].value != "0") {
form.field_name.value = form.name.options[myindex].value;
}
}
//-->


You don't need to hide code from any browser you're going to run into.
The part of a reference that follows a "." cannot be a variable.
If name is a variable, you can't refer to it as "form.name".
You refer to it as form.elements[name], or you simply pass a reference
to the Select object itself, and use its form attribute to refer to
the form that contains it:

<SELECT NAME=\"%s\" onChange=\"fill_desc(this,$field_name)>

<script type="text/javascript">
function fill_desc(select_reference,field_name){
if(select_reference.selectedIndex){ // true if not 0
select_reference.form.elements[field_name].value=
select_reference.options[select_reference.selectedIndex].value;
}
}
</script>

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George Rogic | last post by:
Hello: I've done an exhaustive online search and either can't find what I'm looking for or I'm unable to make what I've found work. I'm not a programmer, but I'm sure that this is probably...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
1
by: Rick Measham | last post by:
I can't find this anywhere, so I hope it can be done: Here's what I can do so far: 1. Certain fields have a class 'textfield' while others are 'textfieldreq'. 2. OnSubmit checks all...
5
by: Good Man | last post by:
Hi there I'm adding form fields on the fly with some javascript DOM programming. I basically just clone a hidden <div>, then adjust node properties to make this new <div> have unique values...
4
by: engwar | last post by:
I'd like to know if it's possible to change the contents of a div tag based on something the user is doing. For example. If there is a text box on a page and the user types his or her name can I...
2
by: Monty | last post by:
I use a SELECT dropdown as the nav interface for jumping to a chosen page number. When I setup up the SELECT element on the page, I want to show the user the current page number they are on, so, I...
3
by: john.dickeson | last post by:
Hello I have been wrestling with a problem, I am trying to change the url of an Iframe from a simple selection box, once the user selects the desired url they wish to visit from the main page the...
2
by: Jason | last post by:
Hi all, I know how to do this the hard way, but I suspect that there's an easier option. I'm creating a program that requires a series of 4 or 6 select menus. Something like this: <select...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.