Results 1 to 4 of 4

Thread: Javascript: Check at least two textboxes are full

  1. #1

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Javascript: Check at least two textboxes are full

    Hey, i have 4 textfields and i need to check that at least two of them are full.

    Would it b better to check it client-side using JS or server-side using PHP?

    Can anyone please help??

    Thanks

  2. #2
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Javascript: Check at least two textboxes are full

    Server Side using PHP, since people can simply turn off Javascript. For convience you can check client side as well, saves the user submitting the form only to find its not done right, and its reduces the amount of work the server has to do, since almost always its going to be full.
    Don't Rate my posts.

  3. #3

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    Re: Javascript: Check at least two textboxes are full

    OK, so... say i do it with Javascript, how do i check that at least 2 of the 4 textfields are not empty.

    And also, how would i do it with PHP if anyone know?

    Thanks, if you know how to do it with either of the languages i would be most grateful

    BIOSTALL

  4. #4
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Javascript: Check at least two textboxes are full

    Are not empty? Not Empty in Javascript is easy, but if you want greater-than-certain-length then it gets abit harder I think, I can't remember all the javascript functions.

    No gurantees that the code is right, I'm to lazy to test.
    Code:
    //Javascript
    if(document.formname.textboxname.value != '') {
      alert('not empty');
    }
    To check atleast 4 aren't empty, you could use a variable to count how many times a textbox is found to be empty (or not empty whichever way you want to look at it ), and after you've done checking each you can check if the variable is greater than 2 or not.
    Code:
    //PHP
    if(trim($_GET["mytextboxname"]) != "") {
      print "No Nullness today :)";
    }
    Don't Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width