Submitting Forms with Unselected Checkboxes

Checkbox control is one of the widely used controls in Web pages. However, it is important to understand that a name/value pair for the checkbox is only submitted with the form when checkbox element is selected (on). If a checkbox is not selected, then the element is not posted to the server with the Form’s submit. As a result, problems may arise since the unselected checkbox is never submitted; your server-side script might not find the checkbox control in the posted name/value pairs. The problem is prominent when your server-side script is updating only the posted values.

If you want to submit an unselected (off) checkbox control with a Form, you may need to write some client-side script to handle this as a workaround. I generally create a hidden type input element and then change its value accordingly by using a JavaScript function. This way, at the server-side, I always know if the user has selected or unselected the checkbox.

This is the JavaScript function to populate the hidden control depending on the checkbox value. Here, ‘frmName’ is the name of the form:

 function ToggleCheckBox(pThis,strControlName) { var oForm = document.forms['frmName']; if (pThis.checked == true) { oForm.elements[strControlName].value='Yes'; } else { oForm.elements[strControlName].value='No'; } } 

These are the checkbox and hidden input controls:

 Checked<%end if%> onclick="javascript:ToggleCheckBox(this,'fldPq');"> 

Note:GetCheckValue method is a server-side function to retrieve the previously saved checkbox values.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a