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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.