+ 1

I want to create a form and based on input data in form, want to use alert function of JavaScript. How can I do this?

Like if Input 1 > Input 2 in form, then display "Buy", else display "Sell". I don't want to use prompt function.

15th Sep 2017, 11:09 AM
VIPUL SHARMA
2 Answers
+ 19
<input type=number onchange=chg()> <input type=number onchange=chg()> <script>function chg(){var tmp=document.getElementsByTagName("input");alert(tmp[0].value>tmp[1].value?"Bye":"Sell")}</script>
15th Sep 2017, 11:28 AM
Valen.H. ~
Valen.H. ~ - avatar
0
Thank you very much @valentinHacker. Only problem still left is, as soon as I enter first number, it executes alert function and shows "Buy" or "Sell" message. But, ideally, it should execute alert function only after both the numbers are entered.
15th Sep 2017, 12:01 PM
VIPUL SHARMA