What I realise from watching videos from coders on youtube is that they make alot of mistakes and they still continue without realising their mistakes so you have to be careful when watching programming videos.
It really frustrated me as I was trying to learn how to validator using jquery some of the coding I was learning wasn't working, learning this at the end of the tutorial.
So that left me struck for quiet a while slowly taking up my time then i came with a theory a conclusion that the person your taking your knowledge from could be wrong.
In other news, i really enjoying coding and look to get better at it. Below is the code to what i did.
<!DOCTYPE html>
<html> <head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script>
$(function(){
function init(){
v= $("#myForm").validate({
rules :{
name:{
required:true,
minlength:2,
maxlength:10,
},
age:{
required:true,
number:true,
},
url:{
required:true
},
agree_1:{
required:true
},
agree_2:{
required:true
}
},
messages :{
name:{
required:"Dont forget your name !",
minlength:$.validator.format("We nee more than {0} ")
}
},
success: function(element){
element.remove();
}
});
}
$.validator.setDefaults({
errorClass :'form-error',
errorElement :'div'
});
$.extend($.validator.messages,{
required:"Go and get him kid",
});
$("#myForm").submit(function(){
var valid=$("#myForm").valid();
if (valid){
$.post('save.php',$(this).serialize(),function(o){
if(o.error=false){
window.location.href='success.php';
}else{
}
},'json');
}
return false;
});
});
</script>
<style>
p {padding:2px;}
</style>
</head>
<body>
<div id="content">
<form id="myForm" method="post" action="" >
<p>Name: <input type="text" class="required"name="name"id="name"></p>
<p>Age : <input type="text" class="required"name="age" id="age"></p>
<p>URL: <input type="text"class="required" name="url"id="url"></p>
<p>Agree_1:
<input type="checkbox" class="required" name="agree_1" id="agree_3">
<label for="agree_3"></label>
</p>
<p>Agree_2:
<input type="checkbox" class="required"name="agree_2" id="agree_2">
</p>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</body>
</html>
Regards
No comments:
Post a Comment