1

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

4
  • 4
    Missing });, Seems error occurred while posting question. Commented Dec 21, 2016 at 7:24
  • Have you included jquery plugin ? Commented Dec 21, 2016 at 7:24
  • Works fine here with proper close braces jsfiddle.net/n6ste5hh Note that <input> is a self closing tag Commented Dec 21, 2016 at 7:26
  • have you included jquery before your form_input_parameter.js and as Satpal said check the closing braces are missing Commented Dec 21, 2016 at 7:26

1 Answer 1

1
  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" />

Sign up to request clarification or add additional context in comments.

1 Comment

Code only answers are virtually meaningless. At least provide an explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.