Question: I'm having problems trying to validate form data from my html file using javascript. For the javascript functions: I want to validate that when a

I'm having problems trying to validate form data from my html file using javascript.

For the javascript functions:

I want to validate that when a checkbox has been checked then a value needs to be entered in the number box corresponding to the checkbox. For example, if the user selects "Cereal" with the checkbox option, I want the javascript program to display an alert as "Please enter a quantity for the selected item" only if they have selected the item but they have not entered a quantity. If the user does not select an item to begin with then the javascript function should not apply.

Also, an alert should pop up if the user tries to enter a quantity value more than 5. Ex. "You cannot enter a value greater than 5."

I also want to validate if the user selects a payment option via radio buttons. For example, if the user does not select a payment option then an alert will pop up prompting the user to select a payment option.

Here is what I have so far on my HTML file:

Grocery Item Selection

Grocery Item Selection

Grains


Select item Item Price Quantity
Cereal $3.00
Rice $4.00
Pasta $5.00



Payment Method

Select payment method:
Visa Master Card Discover

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!