In my current program I want to validate radio boxes. Now I dont want to write out an "if" statement to validate every single radio button checked so i thought it might be easier to make a for loop. With my current loop it shows the same error 4 times. How can I make it show up only once?
ThanksCode:function radioCheck() { for (var i=1;i<=4;i++) { boxName = "pizzaSize" + i; if (!(document.pizzaForm[boxName].checked)) { alert("You must select a pizza size"); } } }
Use a flag to keep track of whether you need to show the alert, and show the alert in an if statement outside the loop.
Thank you for the reply. I am new to Javascript and am not sure how to use a flag to keep track of the alert. Could you please help me?
Thanks
Just default bFlag to false before the loop, and in the loop set bFlag to true if you should show the alert.
Thank you.
edit: Everything working now![]()
Last edited by system32; 02-07-2010 at 02:45 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks