-2

[only enabled field that i fill in][1]

I have a form like picture below. I want all fields disabled except the field that I fill in, when I go to the next field, the previous field that I have filled will be disabled. I've searched but can't figure it out https://i.stack.imgur.com/0ATvQ.png

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
nvrzl
  • 103
  • 1
  • 3
  • 14

1 Answers1

0

You can make read only all field of form and just enabled only one input in which you are typing via below code :

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Vertical (basic) form</h2>
  <form action="/action_page.php" method="post" name="subForm" id="subForm">
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
    </div>
    <div class="form-group">
      <label for="pwd">Password:</label>
      <input type="password" class="form-control" id="password" placeholder="Enter password" name="password">
    </div>
     <div class="form-group">
      <label for="pwd">Number:</label>
      <input type="number" class="form-control" id="number" placeholder="Enter Number" name="number">
    </div>

    <button type="submit" class="btn btn-default">Submit</button>
  </form>
</div>
<script type="text/javascript">
function disableinputs(){
    $("#subForm input").prop('readonly', true);
}
$(document).ready(function(){
    disableinputs();
});
$(document).on('click','#subForm input',function(){
    $(this).prop('readonly', false);
});
$(document).on('focus','#subForm input',function(){
    $(this).prop('readonly', false);
});
$(document).on('focusout','#subForm input',function(){
    disableinputs();
});

</script>
</body>
</html>
Kishan
  • 773
  • 4
  • 10
  • it works thank you kishan, and once more, how the code jquery validation to prevent user go to the next field if user not fill anything – nvrzl Jul 27 '18 at 12:55
  • If answer is right please mark it as right and can please elaborate some more your jquery validation question so I can give you answer in better way... – Kishan Jul 27 '18 at 16:48