Link to home
Start Free TrialLog in
Avatar of Stuart_Johnson
Stuart_Johnson

asked on

onChange event on dropdown fired by PHP

Hi,

I've got a form with a drop down on it.  When the a new item is selected, a bunch of other controls could be enabled or disabled (the onChange event is fired and a method disables or enables these controls).

The contents of the dropdown are automatically populated by a PHP script.  The problem I am having is, when I am re-loading the page, the PHP script sets the correct item index in the dropdown, but the onChange event isn't fired, which means the extra controls are not enabled or disabled.

How can I fire th onChange event from with PHP (or anywhere else) after the items have been added the the correct item has been selected?

Many thanks,

Stuart.
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Hello Stuart_Johnson,

You could use the body onload="somefunction()"


Regards,

Roonaan
Avatar of Stuart_Johnson
Stuart_Johnson

ASKER

I was thinking I could use that, but didn't think it would work.  I suppse that the onLoad event is triggered after the page is rendered, so it should work.

I'll give that a go.  Thanks!
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there anything that could prevent the onLoad event from firing?

Im using:

function test() {
  alert("hi");
}

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="test();">

And the onload isnt being fired (test event).  Any suggestions?  I'm not getting any JS errors from the browser (IE7)

Stuart.
try:

<body onLoad="javascript:alert("Hi")">

Also, try changing "onload" to "onLoad"
There might be another javascript interfering with your test. Do you have other scripts included that fire onload?

An alternative is to have a <script type="text/javascript">test()</script> just in front of your </body>

-r-
Thanks everyone.  I used the PHP logic as suggested, and kept my existing JS and it works fine.

Cheers!