John
John

Reputation: 305

getting input from button not working

Below is my html code for the form

 <form id="taxi_distance_input" >




<div class="col-md-8" style="display: inline-block; left:-30px">
<div class="col-md-4">
<div class="input-group">

  <input type="text" class="form-control" id="usr"> </input>
<span class="input-group-addon" style="width: 50px">km</span>
</div>
</div>
<div class="col-md-4" style="padding-left:0px; margin-left:-10px">

 <input type="button" class="btn btn-success" value="Submit" id="myButton"> </input>

</div>
</div>
<p>&nbsp;</p>
</form>

And in the bottom of the page I give the

<script src="/js/form_input_parameter.js"></script>

Inside the form_input_parameter.js i have written the script

$(document).ready(function(){
    $('#myButton').click(function(){
        var text =  $("#usr").val();
        alert(text+"success");
 });

But it is not working .Any help is apprecited

Upvotes: 1

Views: 41

Answers (1)

keziah
keziah

Reputation: 574

  1. You've forgotten the }); at the end of your JS code
  2. The input tag should end with />

$(document).ready(function() {
  $('#myButton').click(function() {
    var text = $("#usr").val();
    alert(text + " success");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control" id="usr" />
<input type="button" class="btn btn-success" value="Submit" id="myButton" />

Upvotes: 1

Related Questions