Wednesday, 1 August 2012

Validation for required field in javascript:


Hie… Folks I found that I didn’t post my javascript post for validations for required fields… that before I did with javascript then I do that with jquery as I posted earlier pls go through that posted below…..

            Here I did the same as validation for input text fields as below shown picture as here you need to know that about “innerHTML” which make you out from hard code….Here also it will give alert box for the error email input..!!

 function promotioncode() {
   var sel = document.getElementById("state");
     document.getElementById('textmargin7').value = sel.options[sel.selectedIndex].value;
           }
  function validate() {
               var title = document.getElementById('title').value;
               var title1 = document.getElementById('title1').value;
               var titleError = document.getElementById('titleError');
               var titleError1 = document.getElementById('titleError1');
               if (title == '') {

                   titleError.innerHTML = "Name is Required";
               }
               else {
                   titleError.innerHTML = "*";
               }

               if (title1 == '') {
                   titleError1.innerHTML = "Email is Required";
               }
               else if (!emailvalidation(title1)) {
               }
           }
           function emailvalidation(email) {
               var x = document.forms.form.Email.value;
               var atpos = x.indexOf("@");
               var dotpos = x.lastIndexOf(".");
               if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
                   alert("Email is NotValid");
               }
           } 


Output:
             

No comments:

Post a Comment