Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following function:

function updateInput(ish){
    document.getElementById("BetAmount").value = ish;
}

I have the following HTML inputs:

<input class="defaultText" type="number" name="BetAmount" id="BetAmount" onchange="updateInput(this.value)">

<input type="number" name="PotentialGain" id="PotentialGain" />

When users enter in a bet amount number(BetAmount), I would like to instantly show a calculated PotentialGain, which, for example, can be found by multiplying a constant by the specified bet amount entered in by the user.

I'm not very familiar with JavaScript, so any help is greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
512 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...