CrazyEngineers
  • Problem with jQuery

    Pensu

    Member

    Updated: Oct 26, 2024
    Views: 1.8K
    Hello ppl, i have to make a validation code using jQuery. Well, the task is to take username and password from user using a html form and then the form should be validated as in username must be email and none of the field should remain empty.
    Can anyone help me out with this???
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Pensu

    MemberApr 3, 2011

    I have made a code for validation. Here it is:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function() { 
     
        $('#submit').click(function() {  
     
            $(".error").hide();
            var hasError = false;
            var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
     
            var emailaddressVal = $("#uname").val();
            if(emailaddressVal == '') {
                $("#uname").after('<span class="error">Please enter user name.</span>');
                hasError = true;
            }
     
            else if(!emailReg.test(emailaddressVal)) {
                $("#uname").after('<span class="error">Please, Enter a valid username(email).</span>');
                hasError = true;
            }
     
            if(hasError == true) 
    		{ 
    			return false; 
    		}
    		else
    		{
    			window.location="welcome.php";
    		}
     
        });
    });
    </script>
    </head>
    
    <body>
    <form method="post" name="form1" action="">
      <fieldset>
       Username:<input type="text" id="uname" /> <br />
       Password:<input type="password" id="pwd" /> <br />
       <input type="submit" value="Submit" id="submit" />
      </fieldset>
    </form>
    </body>
    </html>
    

    Now, the problem is here that i am not able to redirect user to welcome.php. Help, anyone??
    Are you sure? This action cannot be undone.
    Cancel
  • computeridiot007

    MemberApr 3, 2011

    #-Link-Snipped-# brother has already answered your question brother
    use
    <input type="Button" onClick="check()" />


    insted of
    <input type="submit" onClick="check()" />


    on more thing it's window not windows.Window is default so you can also write location.href.
    And if again it's not working(may be the reason your server is on different port then 80(default)).
    Are you sure? This action cannot be undone.
    Cancel
  • Pensu

    MemberApr 3, 2011

    @computeridiot007: Bro, i guess you didnt see the code i have written above, first of all there is no check function, secondly input type="submit" is working absolutely fine, and thirdly if you see the code you will know that i have used window only. The question mohit answered was different one. The jquery thing is working fine, i have problem in dealing with redirection only. It would be great if you can help me with that.
    Are you sure? This action cannot be undone.
    Cancel
  • Pensu

    MemberApr 5, 2011

    No answers...😔. Anyways i figured it out. If i give the name of php file itself in the form, the code is working fine.
    Are you sure? This action cannot be undone.
    Cancel
  • computeridiot007

    MemberApr 5, 2011

    nicepeeyush
    No answers...😔. Anyways i figured it out. If i give the name of php file itself in the form, the code is working fine.
    brother it worked for me when I change it and then checked out.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register