jquery - My Javascript is not working in localhost XAMPP -


i hope can project school. have piece of html code this:

<!doctype html> <html>     <head>         <title>tambah guru</title>         <link rel="stylesheet" type="text/css" href="stylesheet.css"/>         <script type='text/javascript' src='script.js' charset="utf-8"></script>     </head> <body>  email: <input type='text' id='txtemail' />  <input type='submit' value='simpan' id='validateemail' /> </body> </html> 

and javascript code is:

$(document).ready(function(e) {     $('#validateemail').click(function() {         var semail = $('#txtemail').val();         if ($.trim(semail).length == 0) {             alert('please enter valid email address');             e.preventdefault();         }         if (validateemail(semail)) {             alert('email valid');         } else {             alert('invalid email address');             e.preventdefault();         }     }); });  function validateemail(semail) {     var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-za-z]{2,4}|[0-9]{1,3})(\]?)$/;     if (filter.test(semail)) {         return true;     } else {         return false;     } } 

when run it, not work. don't know why. can me please?

you not adding jquery in above comments. put line above script line in html

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 

and not passing in event object handled. pass event object in click handler in code below. passing event handler in document.ready not need.

$(document).ready(function() {     $('#validateemail').click(function(e) {         var semail = $('#txtemail').val();         if ($.trim(semail).length == 0) {             alert('please enter valid email address');             e.preventdefault();         }         if (validateemail(semail)) {             alert('email valid');         }         else {             alert('invalid email address');             e.preventdefault();         }     }); });  function validateemail(semail) {     var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-za-z]{2,4}|[0-9]{1,3})(\]?)$/;     if (filter.test(semail)) {         return true;     }     else {         return false;     } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -