user1721546 user1721546 - 5 months ago 13
jQuery Question

Jquery code to select value in input box not

I am trying to build a data table that shows some results when parameter values are picked . I started with building a label ,input box and button. I am starting to test trying to retrieve the value entered into the text box.

$(document).ready(function() {
$('#search').submit(function() {
var id = $('#sun').val();
});
});


<div id="page-title">
<h2>sun Details</h2>
</div>
<div class="panel-box col-sm-5">
<div class="form-group">
<label class="col-md-3 control-label">Please enter a sun Number</label>
<div class="col-md-4">
<input type="text" class="form-control" id="sun" placeholder="xxx">
</div>
<button class="btn btn-blue-alt" id="search" type="submit">Search</button>
</div>
</div>

Answer

.submit() is for forms. If you are not using a form, use .click() or $('#selector').on('click', function(){});. Example.

If you are going to use a form, the selector for .submit needs to be the form element.

Comments