We help IT Professionals succeed at work.

onChange event on dropdown fired by PHP

Stuart_Johnson
on
3,399 Views
Last Modified: 2008-01-09
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.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
Hello Stuart_Johnson,

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


Regards,

Roonaan

Author

Commented:
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!
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Commented:
try:

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

Also, try changing "onload" to "onLoad"
CERTIFIED EXPERT
Top Expert 2006

Commented:
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-

Author

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

Cheers!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.