Jump to content

Checked box not running JS code


solarisuser

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/45652-checked-box-not-running-js-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.