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

3rd Aug 2020, 10:57 AM
coal
coal - avatar
2 Answers
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
3rd Aug 2020, 11:49 AM
coal
coal - avatar
3rd Aug 2020, 11:18 AM
RKK
RKK - avatar