Closed Thread
Results 1 to 5 of 5

Thread: How do I get one alert to pop-up in Javascript instead of 4 of the same ones?

  1. #1
    system32 is offline Newbie
    Join Date
    Feb 2010
    Posts
    24
    Rep Power
    0

    Question How do I get one alert to pop-up in Javascript instead of 4 of the same ones?

    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?

    Code:
    function radioCheck()
    	{
    		for (var i=1;i<=4;i++)
    		{
    			boxName = "pizzaSize" + i;
    			if (!(document.pizzaForm[boxName].checked))
    			{
    				alert("You must select a pizza size");	
    			}
    		}
    	}
    Thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,494
    Blog Entries
    75
    Rep Power
    143

    Re: How do I get one alert to pop-up in Javascript instead of 4 of the same ones?

    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    system32 is offline Newbie
    Join Date
    Feb 2010
    Posts
    24
    Rep Power
    0

    Re: How do I get one alert to pop-up in Javascript instead of 4 of the same ones?

    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

  5. #4
    Join Date
    Jul 2006
    Posts
    16,494
    Blog Entries
    75
    Rep Power
    143

    Re: How do I get one alert to pop-up in Javascript instead of 4 of the same ones?

    Just default bFlag to false before the loop, and in the loop set bFlag to true if you should show the alert.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    system32 is offline Newbie
    Join Date
    Feb 2010
    Posts
    24
    Rep Power
    0

    Re: How do I get one alert to pop-up in Javascript instead of 4 of the same ones?

    Thank you.

    edit: Everything working now
    Last edited by system32; 02-07-2010 at 02:45 PM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. help: Convert to alert box
    By wheay in forum PHP Development
    Replies: 5
    Last Post: 05-17-2011, 01:05 AM
  2. newb alert
    By mattmanmm in forum Python
    Replies: 4
    Last Post: 02-10-2011, 11:30 PM
  3. Spammer alert
    By Roger in forum Announcements
    Replies: 44
    Last Post: 10-09-2010, 05:49 AM
  4. Why do I keep getting an empty alert box?
    By system32 in forum JavaScript and CSS
    Replies: 7
    Last Post: 03-11-2010, 10:04 AM
  5. Replies: 5
    Last Post: 02-04-2010, 02:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts