I have a couple of buttons on my form that do mileage calculations and the other updates the cost. These work as expected but they also submit the form.
Here are the fields:
@Html.EditorFor(model => model.Miles, new { htmlAttributes = new { @class = "form-control", @id = "number" } })
<button onclick="roundTrip()">Round Trip?</button>
<button onclick="updatedPrice()">Update Price</button>
@Html.EditorFor(model => model.Cost, new { htmlAttributes = new { @class = "form-control", @id = "price" } })
Here is my JavaScript:
function updatedPrice() {
var price = $("#number").val() * @calcMiles;
var calPrice = price.toFixed(2)
$("#price").val(calPrice);
}
function roundTrip() {
var calc = $("#number").val() * 2;
$("#number").val(calc);
}
Maybe I need to do a replace? Not sure why it submits when I click either one of these.
Thanks for your help!