Skip to content Skip to sidebar Skip to footer

Calculate One Variable Based On Changing Input

I have the following function: function updateInput(ish){ document.getElementById('BetAmount').value = ish; } I have the following HTML inputs:

Solution 1:

Your code is almost correct - you are showing the result in the BetAmount field so no change is visible.

Change your code to:

document.getElementById("PotentialGain").value = ish;

Here's a working demo. I changed the event to onkeyup as onchange only happens on blur - i.e. when a field loses focus.

Solution 2:

Here is the final JQuery function that I used.

functionchangeBet(bet) {
var moneyline = <?php echo json_encode($win) ?>;
var gain = moneyline * bet;
document.getElementById("PotentialGain").value = gain;
}

Along with these inputs:

<input type="text" name="BetAmount[]" id="BetAmount" onkeyup="changeBet(this.value);" >
<input type="number" name="PotentialGain" id="PotentialGain" />

Post a Comment for "Calculate One Variable Based On Changing Input"