Question
Modify the file first_loop.htm so that there is a second text field asking the user how many times they want to be greeted, stipulating that
Modify the file first_loop.htm so that there is a second text field asking the user how many times they want to be greeted, stipulating that it must be between 1 and 20. Then greet them that many times.
Validation: Confirm that value was indeed between 1 and 20. If it is not, output a message reminding them that they must enter a value between 1 and 20, and then do not continue with the function (make the function end). Hint: Remember that a 'return' staement will a function.
If the user enters invalid input, then output the appropriate message (e.g. "You must enter a number between 1 and 20") to a div section called 'errors'. Also set the background color of the invalid text field to yellow.
Note: Each time the user clicks the button, you should remove any output from a previous run of the program. If any errors are present, you should remove any error messages, and remove the yellow background from the text field (by setting the background color to white).
function greetMeThreeTimes()
{
var name = document.getElementById('txtName').value;
for (var counter=0; counter<3; counter=counter+1)
{
$('#greetings').append("Hello, " + name + "
");
}
} //end greetMeThreeTimes
Type in your name and I will greet you 3 times!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started