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.
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.
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!
I'll give that a go. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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"
<body onLoad="javascript:alert("
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">tes t()</scrip t> just in front of your </body>
-r-
An alternative is to have a <script type="text/javascript">tes
-r-
ASKER
Thanks everyone. I used the PHP logic as suggested, and kept my existing JS and it works fine.
Cheers!
Cheers!
You could use the body onload="somefunction()"
Regards,
Roonaan