Scott Windmiller Scott Windmiller - 2 years ago 104
jQuery Question

Increase textbox value by .25

I have a form that has a Service Time field that we want incremented by .25 upon each click of a + button.

I have the following code:

<script language=javascript>
$("#incdec input").val(parseFloat($("#incdec input").val())+0.25);

$("#incdec input").val(parseFloat($("#incdec input").val())-0.25);

and the HTML part:

<div class="form-group" id="incdec">
<label for="Time" class="col-sm-2 control-label">Time:</label>
<div class="col-sm-10"><input name="Time" value="<%=rs.Fields.Item("Time")%>"></div>
<button id="up">+</button>
<button id="down">-</button>

This works just fine but upon clicking the + or - it increases/decreases but also submits the form it's in. I want to be able to just increase/decrease what is in the text field then submit the form with another button.

I know I am missing something stupid here!

Answer Source

The type attribute of a button defaults to "submit". You'll want to add type="button" to prevent submission from occurring.


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