Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  127] [ 6]  / answers: 1 / hits: 16477  / 8 Years ago, thu, july 14, 2016, 12:00:00

So basically I have a for loop and I am trying to get it to run x amount of times. Depending on what the user inputs. The issue I am having is how to get the user input and also make sure that its a number not any other type of input. making them try again if its wrong.


More From » html

 Answers
7

It's simple really



Input Number : <input id=numberinput onkeypress=return event.charCode >= 48 && event.charCode <= 57 />

<button id=btn onclick=doAction()>
Send
</button>

<script>
var doAction = function () {
var input = document.getElementById('numberinput');
var times = parseint(input.value);

for(var i = 0; i < times; i++) {
//do whatever you need to do
}
}
</script>

[#61381] Tuesday, July 12, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aricl

Total Points: 215
Total Questions: 91
Total Answers: 94

Location: Venezuela
Member since Thu, Jul 15, 2021
3 Years ago
aricl questions
Mon, Aug 2, 21, 00:00, 3 Years ago
Mon, Aug 3, 20, 00:00, 4 Years ago
Thu, Feb 13, 20, 00:00, 4 Years ago
Wed, Oct 23, 19, 00:00, 5 Years ago
;