Web Analytics Made Easy -
StatCounter Making a checkbox required for a button - CodingForum

Announcement

Collapse
No announcement yet.

Making a checkbox required for a button

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making a checkbox required for a button

    I am trying to make a checkbox required in order to select the registration button.
    Here is the jsfiddle
    Edit fiddle - JSFiddle

    A couple problems...
    1) What works in the jsfiddle does not work in the forum registration
    You can see here
    Python Forums - Registration Agreement
    For example if you click and unclick the check box in jsfiddle, it works....but the same code in the registration field does not work.
    2) I cant get the initial checkbox to be empty. If i set the value to false

    I would like the register button to be not checked when first opening, and the button to be unable to click if the checkbox is not clicked.

  • #2
    The checked attrribute is setting the checkbox to be checked to start with. You need the required attribute instead so as to enforce that it must be checked by the user without checking it for them.

    Code:
    <input type="checkbox" required id="checky" value="off">
    You then don't need any JavaScript to test if it is checked or not as the updated HTML already covers that test.

    Your form really looks like it needs a lot of changes to the HTML in order to bring it out of 1997 (when much of the code you are using was flagged as obsolete eg. the align attributes and many of the things you should be using eg. <label> were introduced).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

    Comment


    • #3
      The checked attrribute is setting the checkbox to be checked to start with.
      Ah thank you, i was thinking the value should be a boolean or something. AFter changing this it only registers after you click it once?

      You then don't need any JavaScript to test if it is checked or not as the updated HTML already covers that test.

      Your form really looks like it needs a lot of changes to the HTML in order to bring it out of 1997 (when much of the code you are using was flagged as obsolete eg. the align attributes and many of the things you should be using eg. <label> were introduced).
      I would like to do it as to leave the majority of the original code as is. The code is from MyBB Forum software. Im just a python coder, not really great with JS or html. I dont want to start updating the code as MyBB Forum support wont know why its not the original code. I assumed that a checkbox addition was not going to be that hard, but i guess i was wrong.

      Is there any way to do it with the 1997 version?

      You then don't need any JavaScript to test if it is checked or not as the updated HTML already covers that test.
      updated as the snippet you have shown or updated as the 1997 to now? I added the required and removed the checkbox attribute. But i dont know what to do to the register button to make that valid.
      Last edited by metulburr; Sep 28, 2016, 06:57 AM.

      Comment


      • #4
        anyone?

        Comment


        • #5
          Originally posted by metulburr View Post
          Is there any way to do it with the 1997 version?
          Do you have a copy of Netscape 2 to test in?

          JavaScript is now a completely different language to what it was in 1997 - there would be less in common between the 1997 and 2016 versions of JavaScript than there is between Python and PHP.
          Stephen
          Learn Modern JavaScript - http://javascriptexample.net/
          Helping others to solve their computer problem at http://www.felgall.com/

          Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

          Comment


          • #6
            Do you have a copy of Netscape 2 to test in?
            Im running in ubuntu 16.04. Im pretty sure i could find old browsers to run somewhere. Would i really need to? The code is running in current day browsers.

            JavaScript is now a completely different language to what it was in 1997 - there would be less in common between the 1997 and 2016 versions of JavaScript than there is between Python and PHP.
            oh i didnt know this

            I guess i could change the button code to update. But if that requires more code to update, and that requires more code to update, etc. etc., then i might be getting into too much. But if i just had to change out the tags for button itself, then i dont see a problem. (unless that breaks the forum software).

            Comment

            Working...
            X