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

DOM select onchange javascript

I have a function called populate which populate a select box. I need
it to run when a different select box value is chnage. So I need the
event onChange.

But i need to pass it two var to. how do i do this??

object.onchange = ..

What do I made it equal to for the above. if the typename = 'type1' and
itemname = 'item1'.

Can I do setAttribute or some think??

Thanks

Donald

function populate(typename,itemname)
{
if (!optionTest) return;
var type = document.forms[formname].elements[typename];
var number = type.options[type.selectedIndex].value;
alert(number);
if (!number) return;

var list = items[number];
var item = document.forms[formname].elements[itemname];
item.options.length = 0;
if (number == 0) {
item.options[0] = new Option('Pick Item ---->','');
alert('');
return;
}
for(i=0;i<list.length;i+=1)
{
item.options[i] = new Option(list[i],'');
}
};

Jul 30 '06 #1
2 17616
donald wrote:
I have a function called populate which populate a select box. I need
it to run when a different select box value is chnage. So I need the
event onChange.

But i need to pass it two var to. how do i do this??

object.onchange = ..

What do I made it equal to for the above. if the typename = 'type1' and
itemname = 'item1'.
Forgive for asking what seems to me to be the obvious. Why change the
onchange function when you can alter what that function does?

<select onchange="doThis()">
....

var global_flag;

function doThis(){
if(global_flag == 'some_value'){do this...}else{do that...}
}

Jeff
>
Can I do setAttribute or some think??

Thanks

Donald

function populate(typename,itemname)
{
if (!optionTest) return;
var type = document.forms[formname].elements[typename];
var number = type.options[type.selectedIndex].value;
alert(number);
if (!number) return;

var list = items[number];
var item = document.forms[formname].elements[itemname];
item.options.length = 0;
if (number == 0) {
item.options[0] = new Option('Pick Item ---->','');
alert('');
return;
}
for(i=0;i<list.length;i+=1)
{
item.options[i] = new Option(list[i],'');
}
};
Jul 30 '06 #2
donald wrote:
I have a function called populate which populate a select box. I need
it to run when a different select box value is chnage. So I need the
event onChange.

But i need to pass it two var to. how do i do this??

object.onchange = ..
Presumably you want to know how to dynamically set an onchange handler
using a function that requires parameters, so:

object.onchange = function(){
someFunction(parm1, parm2);
}
Your next question will be 'how do I set the values of parm1 and
parm2?'.

What do I made it equal to for the above. if the typename = 'type1' and
itemname = 'item1'.
object.onchange = function(){
someFunction('type1', 'item1');
}

Is that what you want? You can do:

object.onchange = function(){
var param1 = 'type1';
var param2 = 'item1';
someFunction(param1, param2);
}
That creates a closure (in this case a completely unnecessary one) back
to the anonymous function, which may have complications.

Can I do setAttribute or some think??
[...]
function populate(typename,itemname)
Please indent code with 2 (preferred) or 4 spaces and manually wrap at
about 70 characters. Allow for a couple of quoted replies too.

{
if (!optionTest) return;
Where is optionTest declared or initialised? It doesn't seem to get
used anyway.

var type = document.forms[formname].elements[typename];
Where is formname initialised?

var number = type.options[type.selectedIndex].value;
alert(number);
if (!number) return;

var list = items[number];
Where was items initialised?

[...]

You are better to post an example or link that is a minimal example of
what you are trying to do. Search the archives for 'dependent select
options' or 'dynamic select list'.

Try:
<URL: http://www.javascripttoolbox.com/lib/dynamicoptionlist/ >
--
Rob

Jul 31 '06 #3

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

Similar topics

4
by: point | last post by:
Hello there... I'm a PHP programmer and starting to learn JS... I have a following problem.... I have 3 select boxes! one is hotel one is destination and one is country... if someone...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
1
by: fig000 | last post by:
Hi, I want to use a select object in asp and have the user pick something from this select and have javascript open a window fired by an event. Once the new window is open it displays another...
5
by: Bart | last post by:
When I put the following code on a page the image on the page changes when I mouse over the links. Now I was thinking I could instead create a popup menu to change the image on the page, see second...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
2
by: VK | last post by:
A while ago there was a discussion how to implement a select list that would call a function right upon new selection is being made w/o clicking any additional buttons: ...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
14
by: The Natural Philosopher | last post by:
This is a nasty one and I can't see my way out of it. I have a bunch of select statements in a form, and each select statement has an onchange="do_something(this)" in it, and this works...
1
by: akoymakoy | last post by:
Good Day I have these line of codes in my javascript ...... if (selObj.type == 'text' ) { parentObj = document.getElementById('destinationCity').parentNode; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.