Web Analytics Made Easy -
StatCounter Automatically check a checkbox on form? - CodingForum

Announcement

Collapse
No announcement yet.

Automatically check a checkbox on form?

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

  • Automatically check a checkbox on form?

    Hi, I have a form here: http://www.lps.surepayroll.com/testa...HR-44854Y.html

    I don't have access to edit the code for the form, but I can drop in javascript at the top of the page. I'm trying to have the checkbox already be checked when the user gets to this page. Is this at all possible, without being able to edit the form code?

  • #2
    you're using jQuery in your script but you are not actually loading jQuery. You need to download it or link to it for your script to do anything.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

    Comment


    • #3
      Ok it's now linked but the checkbox still does not prepopulate. Here's the script I used:

      Code:
      <script type="text/javascript">
      $(function()
      {
      if(window.location == "http://www.lps.surepayroll.com/testaccountsem/pg-2-1427HR-44854Y.html")
      {
      if($('#ballform_optin_0').prop('checked','false')) {
      {
      $('input[name=ballform_optin_0]').attr('checked', true);
      }
      }
      }
      });
      </script>

      Comment


      • #4
        Code:
        $(function(){
        	if(window.location == "http://www.lps.surepayroll.com/testaccountsem/pg-2-1427HR-44854Y.html"){
        		if(!$('#ballform_optin_0').is(':checked')){
        			$('#ballform_optin_0').attr('checked', 'checked');
        		}
        	}
        });
        That do it?
        Stop making things so hard on yourself.
        i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

        Comment


        • #5
          Yes sir that does it perfectly. 1 question - instead of making sure the URL is that full path, can we instead just verify that the domain is "http://www.lps.surepayroll.com/"?

          So, if the domain is http://www.lps.surepayroll.com/ (no matter what follows in the URL) then the checkbox is checked?

          Comment


          • #6
            yep,

            note I'm testing on localhost:

            Code:
            if(document.domain == "localhost"){
            I think you can use "www.lps.surepayroll.com" but might need some testing to make sure.
            Stop making things so hard on yourself.
            i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

            Comment


            • #7
              Yep, that works. Thanks a lot.

              Comment


              • #8
                Ok, now the checkbox is not checked.

                http://www.lps.surepayroll.com/testa...HR-44854Y.html

                I swear this worked yesterday...

                Comment


                • #9
                  if(document.domain == "www.lps.surepayroll.com"){

                  try that
                  Stop making things so hard on yourself.
                  i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

                  Comment


                  • #10
                    One sidenote here
                    Code:
                    if($('#ballform_optin_0').prop('checked','false')) {
                    This will not(!) check whether a checkbox is checked but rather uncheck the checkbox and then continue with the TRUE part of the "if" because the result of a .prop() set operation is the jQuery object itself and this will always be evaluated as TRUE inside "if".

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎