+ 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.
2 ответов
+ 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>
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.