Require check in box

by 8 replies
9
How do I make a form submit button active only if a single option box is checked (or ticked), preferably onpage, and in php?

Thanks, and...

Be Well!
ECS Dave
#programming #box #check #require
  • Use radio buttons instead of checkboxes. Checkboxes are for multiple choices, radio buttons are for single choice. Radio buttons won't allow multiples.
    • [1] reply
    • Thanks for your reply SteveJohnson!

      I have only one checkbox though, it's either checked, or not...
      I want to require that it be checked, before the submit button can be pressed.

      Be Well!
      ECS Dave
      • [1] reply
  • JavaScript is the way to do this.

    Use the "onclick" event of the checkbox to call a script that tests the checkbox value. If it's selected then alter the "disabled" parameter of the button.

    An example of this is at How to Enable / Disable Submit Button using Javascript According to any CheckBox is Checked on a WEB Page

    Bill
    • [1] reply
    • Bill,

      I tried that (as instructed on the page), and still the button can be pressed... :confused:

      I truly appreciate your input though!

      Be Well!
      ECS Dave

      P.S. IE says something about
      Code:
      'document.getElementById(...)' is null or not an object
  • Silly question Dave, but you did change the values in the sample code to the actual id's of the elements on your page, correct? Just asking because of your IE error.

    Another tutorial that shows this in action is JAVASCRIPT: Disable/Enable A Submit Button When Checkbox Is Selected/Deselected ie. Checked/Unchecked. There is a sample on the page, you might want to try it with IE first - if it works there is should work in your code.

    Another article, a rather long one, can be found here: Enabling/ disabling form elements using JavaScript . It actually deals with using JavaScript to disable items in general.

    Hope this helps

    Bill
    • [1] reply
    • After reading the page here - The disabled attribute of HTML 4 - I was able to cobble something together that is working now... Thanks!

      Be Well!
      ECS Dave

      P.S. I had wanted the checkbox outside of the form, but that was apparently not possible with the way my form is set up. Can't change that, but I did move the checkbox inside the form, and all's good. Thanks again.
  • what ever the changes are done, it is better to check it once in IE. I have also faced lot of errors and mostly the errors will be with JavaScript.

Next Topics on Trending Feed