Solved

drop down list boxes onchange events

Posted on 2010-08-20
14
671 Views
Last Modified: 2013-12-13
I have two php drop down list boxes with the following names:
"txtNme1"
"initsel1"

The "txtNme1" box has a list of names being populated from a database list
The "initsel1" box has a list of integers 1 to 60 , beind populated from a database list
 
I simply want to add an onchange event to the "txtNme1" such that any selection will set the "initsel1" box to a selection of 1
0
Comment
Question by:doctorbill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 14

Expert Comment

by:sam2912
ID: 33487884

<script type="text/javascript">
window.onload = function() {
    document.getElementsByName("txtNme1")[0].onchange = function() {
        document.getElementsByName("initsel1")[0].selectedIndex = 0;
    }
}
</script>

Open in new window

0
 

Author Comment

by:doctorbill
ID: 33487946
how is this function called from the txtNme1 dropdownlist box ?
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33487972
<select onchange='document.getElementsByName("initsel1")[0].selectedIndex = 0;' name='txtNme1'>
<option></option>
...
<option></option>
</select>
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33487981
ps. if that works for you, please award points to sam2192
0
 

Author Comment

by:doctorbill
ID: 33488039
nothing happens
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33488061
so maybe a dumb question, but in  your initsel box, is the first item an empty spot or 1?
0
 

Author Comment

by:doctorbill
ID: 33488067
empty
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33488077
<select onchange='document.getElementsByName("initsel1")[0].selectedIndex = 1;' name='txtNme1'>
0
 
LVL 14

Expert Comment

by:sam2912
ID: 33488168
It will have been more helpful if you had posted the generated HTML code for both select fields.
0
 

Author Comment

by:doctorbill
ID: 33488207
it works but in dreamweaver, instead of seeing the text box as before, I see the following on the page:

<select name="txtNme1" class="input_boxes_orders_add" id="txtNme1" onchange='document.getElementsByName("initsel1")[0].selectedIndex = 1;' name='txtNme1'>
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33488227
well you can remove the last part that says name='txtNme1' as you already have that right after the select. Other than that I am not sure why it would display like that in dreamweaver as I don't use dreamweaver.
0
 
LVL 14

Accepted Solution

by:
sam2912 earned 500 total points
ID: 33488237
Now you are confusing us. Are there two select boxes or is there a "text box"??

Besides, in your previous code, there are two name attributes. Remove one of them.

Also, the code I provided in the first post assumes you only have one of "txtNme1" and "initsel1" on the page, as you did not state that there are multiple.

So, what is? Please explain in detail and provide generated code.
0
 

Author Comment

by:doctorbill
ID: 33488268
message to jrm213jrm213:
Correct - there was a duplicate name. It now works fine
Thanks for your help and consideration for Sam

sam2912:
Sorry - in future I will be more precise with my code
Thanks very much
0
 

Author Closing Comment

by:doctorbill
ID: 33488273
Very fast and professional responses
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question