Reputation: 105
I have a really easy HTML form and some JQuery to calculate a figure.
The issue I have is that the if statement returns the same number irrelevant of the input:
$(document).ready(function()
{
$('input').change(function()
{
var behind = escape($('#behind').val());
var speed = parseInt($('#speed').val());
var diff;
if (behind = "nse") { diff = '0.83'; }
if (behind = "0.5") { diff = '1.66'; }
if (behind = "0.75") { diff = '2.49'; }
var hsr = speed-diff;
$('#hsr').html(hsr);
});
});
If I input nse into the box the calculation uses diff = '2.49' instead of diff = '0.83' as I've programmed.
The jsFiddle page with the full code is at http://jsfiddle.net/Jucna/1/
Please could someone explain what is wrong with the code?
Thanks in advance.
Upvotes: 1
Views: 57
Reputation: 12390
Missing a =
in your if statements
if (behind == "nse") { diff = '0.83'; }
if (behind == "0.5") { diff = '1.66'; }
if (behind == "0.75") { diff = '2.49'; }
Using one =
assigns a value rather than comparing it.
Upvotes: 1