Saturday, 9 June 2018


//create simple form using bootstrap  and validate their field  using java script..........


<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>

<body>

<div class="container">
<h1 class="text-success text-center">User Registration Form</h1>
<div class="col-lg-8 m-auto d block">

<form action="#" onsubmit="return validation()" class="bg-light">
<div class="form-group">
<label>User Name:</label>
<input type="text" name="user" class="form-control" id="user" autocomplete="off">
<span id="username" class="text-danger font-weight-bold"></span>
</div>

<div class="form-group">
<label>Password:</label>
<input type="text" name="pass" class="form-control" id="pass" autocomplete="off">
<span id="password" class="text-danger font-weight-bold"></span>
</div>

<div class="form-group">
<label>Confirm Password:</label>
<input type="text" name="cnfpass" class="form-control" id="cnfpass" autocomplete="off">
<span id="cnfpassword" class="text-danger font-weight-bold"></span>
</div>

<div class="form-group">
<label>Mobile No:</label>
<input type="text" name="mobile" class="form-control" id="mobile" autocomplete="off">
<span id="mobileno" class="text-danger font-weight-bold"></span>
</div>
<div class="form-group">
<label>Email:</label>
<input type="text" name="email" class="form-control" id="email" autocomplete="off">
<span id="emailid" class="text-danger font-weight-bold"></span>
</div>
<input type="submit" name="submit" value="submit" class="btn btn-success">  
</form>
</div>
</div>

<script type="text/javascript">
function validation() {

var user=document.getElementById('user').value;

var pass=document.getElementById('pass').value;

var cnfpass=document.getElementById('cnfpass').value;

var mobile=document.getElementById('mobile').value;

var email=document.getElementById('email').value;

if(user==' ')
{
document.getElementById('username').innerHTML="** please fill the User Name field";
//alert('required');
return false;
}



if(pass==' ')
{
document.getElementById('password').innerHTML="** please fill the Password field";
//alert('required');
return false;
}

if(cnfpass==' ')
{
document.getElementById('cnfpassword').innerHTML="** please fill the Confirm Password field";
//alert('required');
return false;
}

if(mobile==' ')
{
document.getElementById('mobileno').innerHTML="** please fill the mobile number field";
return false;
}

if(email==' ')
{
document.getElementById('emailid').innerHTML="** please fill the email  field";
return false;
}

}


</script>


</body>
</html>







No comments:

Post a Comment