Results 1 to 4 of 4

Thread: JavaScript for required field not blanked.

  1. #1
    SmithJohnson is offline Senior Member
    Join Date
    Dec 2009
    Posts
    364
    Rep Power
    3

    Default JavaScript for required field not blanked.

    Hi. I am developing one windows application. In that application one form is there, in this form some field is there like Username, birth date etc. I want to right JavaScript for user if the users not enter the field then it gives the error message. Kindly help me on how to get rid of this problem.

  2. #2
    Williamsjones is offline Senior Member
    Join Date
    Dec 2009
    Posts
    352
    Rep Power
    3

    Default

    I suggest you to refer following example of JavaScript, which will give you something idea about the use of this:

    Code:
    <script language="JavaScript" type="text/javascript">
    //You should create the validator only after the definition of the HTML form
     var frmvalidator = new Validator("myform");
     frmvalidator.addValidation("FirstName","req","Please enter your First Name");
     frmvalidator.addValidation("FirstName","maxlen=20",
    "Max length for FirstName is 20");
     frmvalidator.addValidation("FirstName","alpha");
     
     frmvalidator.addValidation("LastName","req");
     frmvalidator.addValidation("LastName","maxlen=20");
     </script>

  3. #3
    DavisNelson is offline Senior Member
    Join Date
    Dec 2009
    Posts
    202
    Rep Power
    3

    Default

    Code:
    <script type="text/javascript">
        
            function RegainFocus() 
           {
                if((document.getElementById("txt_name").value).length == “”) 
               {
                    document.getElementById("txt_name").focus();
                    alert("Please Enter Name");
                }
            }        
        
        </script>

  4. #4
    TorresScott is offline Senior Member
    Join Date
    Dec 2009
    Posts
    239
    Rep Power
    3

    Default

    Refer following script:

    Code:
    function verify() {
    var errormess = "Please fill following fields: ";
    if (document.form.first.value=="") {
    errormess = errormess + " - First Name";
    }
    if (document.form.last.value=="") {
    errormess = errormess + " -  Last Name";
    }
    if (document.form.email.value=="") {
    errormess = errormess + " -  E-mail";
    }
    //alert if fields are empty and cancel form submit
    if (errormess == "You are required to complete the following fields: ") {
    document.form.submit();
    }
    else {
    alert(errormess);
    return false;
       }
    }
    //  End -->
    </script>
    The script that I have mentioned will definitely help you.

Similar Threads

  1. How to use Gmail for hosting a field Name
    By PerrySullivan in forum General Internet Terms
    Replies: 2
    Last Post: 07-20-2010, 02:23 PM
  2. Modify field Name in SharePoint
    By FosterWood in forum General Internet Terms
    Replies: 0
    Last Post: 03-22-2010, 04:27 PM
  3. Replies: 0
    Last Post: 12-19-2009, 11:38 PM
  4. suggestions required
    By subzero in forum General Networking
    Replies: 1
    Last Post: 11-24-2009, 10:58 AM
  5. Creating sound field of large-size
    By Estevan in forum Speaker
    Replies: 1
    Last Post: 08-11-2009, 06:14 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48