Jump to content

Problem With Checkbox Value In Javascript Onload()


Recommended Posts

I am setting up an update form which can be used in two different ways, by hiding or displaying fields. 
The way the form detects which of the two sets of fields to display is by a checkbox field. The form also sets this checkbox field so that the next time the form is used the fields that were hidden become visible and the visible ones become hidden. 
The problem is that on loading the form the checkbox value is always read as 'Y'. I try setting this to 'N' or 'No' in the javascript but it doesn't make any difference even when the form is updated and then re-used. 
I am using chrome and windows XP

Link to comment
Share on other sites

Hello ab2013,

 

If I understand correctly, it is better to use the Checked property.

Example,

function is_checked_and_change()
{
   var is_checked = document.getElementById("id").checked;

   if (is_checked)
      {
         document.getElementById("id").checked=false;
      }
   else
      {
         document.getElementById("id").checked=true;
      }
}

The function checks if the checkbox is checked.

If the checkbox is checked, the function unchecks it and vice versa.
Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...