click to return false, click again to return true javascript | Sololearn: Learn to code for FREE!

0

click to return false, click again to return true javascript

I have one (if) and one (else if) and (else) I want something like this: when the user clicked on the button for the first time the (else if) statement will be executed and when the user clicked on the button for the second time the (else if) not to be executed This is my code <!DOCTYPE html> <html> <body> <p>Please input a number between 1 and 10:</p> <input id="numb"> <button type="button" onclick="myFunction()">Submit</button> <p id="demo"></p> <script> function myFunction() { var x, text; x = document.getElementById("numb").value; if (isNaN(x) || x > 10) { text = "Input not valid"; } else if (x < -1) { text = "X is less than 0" } else { text = "Input OK"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html> I hope you guys understood what I want to do, and what's my goal

8/3/2020 10:57:28 AM

coal

2 Answers

New Answer

0

rohit It's not what I meant I want else if to be executed once and when the button clicked for the second time else if be disabled

+2

This works for me well. https://code.sololearn.com/WBwqinzO2gDl/?ref=app