Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    445
    Thanks
    7
    Thanked 3 Times in 3 Posts

    what is the opposite of undefined when checking if a form field is filled or not

    What I am wanting to do is have my form open up a new part of the form when the previous sections are filled out.

    i.e

    name field shows, when it has content, the next field opens up for it to be filled out, and so on.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,700
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    The opposite of “undefined” is “not undefined”, i. e. either != 'undefined' or check if it’s not empty: != ''

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Are you looking for something like this?

    Each field needs to be validated, with e.g. a minimum length and characters according to the field, e.g. a proper name may contain only letters, hyphen, apostrophe (and perhaps spaces). Telephone numbers and email addresses must be validated appropriately. Only if the validation is passed will the next textbox be revealed. If not a suiatble message should be shown, the textbox cleared, and the focus returned to it.

    Be aware that the user may possibly backtrack and change a previously validated entry.


    Code:
    NAME <input type = "text" id = "uname" onblur = "showNext(this,2)">
    <br>
    <span id = "text2"  style="display:none" >
    ADDRESS <input type = "text" id = "uaddress"  onblur = "showNext(this,3)">
    </span>
    <span id = "text3" style="display:none">
    EMAIL <input type = "text" id = "uemail"  onblur = "showNext(this,4)";
    </span>
    
    <script type = "text/javascript">
    function showNext(which,num) {
    
    var val = which.value;
    // validate user entry here as per num, return false if validation not passed.  if (num==2) { //validate name field, if (num==3) { // validate address field etc.
    
    // only if validation returns true
    var next = "text" + num;
    document.getElementById(next).style.display="block";
    }
    
    </script>

    Quizmaster: In maths, what number is represented by 10 to the power of 3?
    Contestant: Six.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by VIPStephan View Post
    The opposite of “undefined” is “not undefined”, i. e. either != 'undefined' or check if it’s not empty: != ''
    != 'undefined' is almost always true.
    i think you meant != undefined; ...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

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