Click to See Complete Forum and Search --> : how to fire onchange programmatically?


dotNetCoder
03-14-2005, 02:43 AM
Hello all.
I have an urgent question and I wish someonene could answer:
Is it possible to fire the onchange (for a dropdownlist) event programmatically from javascript?
Actually I have created a function to link two Dropdownlists in a Parent-Child relation, but the problem is that if I have more than two level relation betwen my DDLs, the onchange event doesn't fire for the non direct ChildDDL.

For example, I have a function
loadChildOptions(ParentDDL, ChildDDL){
//function to change ChildDDL options relatively to ParentDDL
//ChildDDL.options.add(...);
//ChildDDL.selectedIndex=0; but the onchange event of ChildDDL doesn't fire
}
I need to fire the onchange for ChildDDL from the loadChildOptions function.
Any idea about this?

Pittimann
03-14-2005, 03:01 AM
Hi!

What you are trying to do doesn't have anything in common with the firing of events. Do you simply want the child dropdown's first option to be selected after having populated it? If so, put what you have AFTER the loop creating the options or say 'ChildDDL.options[0].selected=true' after having populated the dropdown.

Hard to say where you exactly have to put it because your snippet doesn't provide any information what you are doing.

Cheers - Pit

dotNetCoder
03-14-2005, 03:26 AM
Hi Pittimann, thx for your reply.
Unfortunately I don't have the load loadChildOptions function body now but it's runing 100%.
Let me explain the problem with this example:
Suppose I have 3 related Dropdownlists:
DDLCountries > DDLCities > DDLStreets
and this is the definition of my function prototype:
function loadChildOptions(cmbParentDDLID, cmbChildDDLID, arrChildOptions)
{
//code to load cmbChildDDL options
}
<Select id=DDLCountries onchange="loadChildOptions('DDLCountries','DDLCities ',arrCitiesOptions);">
<Select id='DDLCities onchange="loadChildOptions('DDLCities ,DDLStreets',arrStreetOptions);">
<Select id=DDLStreets>

So the problem is that when I click on DDLCountries, the DDLCities is loaded with the correct options but the onchange event doesn't fire on DDLCities, and so DDLStreets keeps the old options.
I hope this example is clear.

Pittimann
03-14-2005, 03:36 AM
Hi!Originally posted by dotNetCoder
Unfortunately I don't have the load loadChildOptions function body now but it's runing 100%But the modifications which you need will have to take place there. And one of the modifications you seem to need is to clear the streets' select whenever the country is changed and to populate it when a city is selected.

Cheers - Pit

dotNetCoder
03-14-2005, 05:25 AM
Hi.
I have tried ChildDDL.onchange(); and it's working now