bateman's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
23 (0.04 per day)
Joined:
01-February 13
Profile Views:
807
Last Active:
User is offline Mar 08 2013 02:59 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   bateman has not set their status

Posts I've Made

  1. In Topic: jquery validation check at least 1 checkbox has been checked

    Posted 6 Mar 2013

    View PostDormilich, on 06 March 2013 - 05:04 AM, said:

    what do you need the countChecked() function for?


    Thanks, i solved the issue.
  2. In Topic: jquery validation check at least 1 checkbox has been checked

    Posted 6 Mar 2013

    View PostDormilich, on 05 March 2013 - 11:07 PM, said:

    hm, how do I explain it ... why donít you combine both functions into one?


    I have come up with this script but it does not work and i don't know why :(/>

     <script>
        
       function validateForm()
    {
      var n = $( "input:checked" ).length;
    
    countChecked();
     
    $( "input[type=checkbox]" ).on( "click", countChecked );
    
    if (n==0)
      {
      alert("You must choose an item");
      return false;
      }
      else return true;
    } 
      
    </script>
    
  3. In Topic: jquery validation check at least 1 checkbox has been checked

    Posted 5 Mar 2013

    View PostDormilich, on 05 March 2013 - 01:20 PM, said:

    correct, you need variable n.


    Thanks, Annoyingly it still isn't working. Here is the up to date code:

     <form name="validate" action="page2.php" onsubmit="return validateForm(this);" method="post"> 
    .....
    <input type='checkbox' name='$item'>
    <input type="submit" value="Submit">
     <script>
    var countChecked = function() {
      var n = $( "input:checked" ).length;
    };
    countChecked();
     
    $( "input[type=checkbox]" ).on( "click", countChecked );
    
       function validateForm()
    {
    if (n==0)
      {
      alert("You must choose an item");
      return false;
      }
      else return true;
    } 
      
    </script>
    </form>
    


    Can you see anything wrong?
  4. In Topic: jquery validation check at least 1 checkbox has been checked

    Posted 5 Mar 2013

    View PostDormilich, on 05 March 2013 - 01:13 PM, said:

    View Postbateman, on 05 March 2013 - 09:06 PM, said:

    (jquery to js)

    jQuery *is* JS, thatís the magic.


    oh - okay, how do i reference the variable i need from script 1 in script 2? I am assuming its the variable n i need from script 1. Thanks
  5. In Topic: jquery validation check at least 1 checkbox has been checked

    Posted 5 Mar 2013

    View PostDormilich, on 05 March 2013 - 12:48 PM, said:

    hint: you donít need the lines #8 and #18.


    I knew about line #8 having to be removed. But now how do i parse the variable from script 1 to script 2? (jquery to js)

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

bateman hasn't added any friends yet.

Comments

bateman has no profile comments yet. Why not say hello?