user1721546 user1721546 - 1 year ago 102
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 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">
<button class="btn btn-blue-alt" id="search" type="submit">Search</button>

Answer Source

.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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download