solarisuser Posted April 5, 2007 Share Posted April 5, 2007 Hi All, I have this JS code that uses a checkbox to show or hide fields. If checked, it will show the fields that are hidden by default. <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- function showHideSelection() { if (document.form1.gor.checked) { if (document.layers) document.layers[\'formdiv\'].visibility = "show"; else document.getElementById(\'formdiv\').style.visibility = "visible"; } else { if (document.layers) document.layers[\'formdiv\'].visibility = "hide"; else document.getElementById(\'formdiv\').style.visibility = "hidden"; } } //--> </SCRIPT> Then in the PHP page, I have this: <form name="form1"> <input type="checkbox" name="gor" onclick="showHideSelection();"> Toggle </form> When I physically click on the checkbox, it shows the hidden fields. However, when I have "checked" in that input type, like so: <input type="checkbox" checked name="gor" onclick="showHideSelection();"> Toggle the checkbox is checked, but the JS code is not executed and the hidden fields are not shown. It looks as though I'm not doing something right, could someone please correct me? Thanks! Quote Link to comment Share on other sites More sharing options...
mainewoods Posted April 10, 2007 Share Posted April 10, 2007 <body onload="showHideSelection();"> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.