How do I keep this function from playing out every "if" scenario?

Here's my code:

function IsEmpty(){
	if(document.getElementById("toc_r").checked == false && document.getElementById("toc_t").checked == false && !document.getElementById("date").value &&!document.getElementById("edate").value)
	{
		alert("Please be sure to enter some kind of search criteria!")
	}
	if(document.getElementById("toc_r").checked == false && document.getElementById("toc_t").checked == false && document.getElementById("date").value)
	{
		alert("Please be sure to check either \"rank\" or \"trended.\"")
	}
	if(document.getElementById("toc_r").checked == false && document.getElementById("toc_t").checked == false && document.getElementById("edate").value)
	{
		alert("Please be sure to check either \"rank\" or \"trended.\"")
	}
	if(document.getElementById("toc_r").checked == true || document.getElementById("toc_t").checked == true && !document.getElementById("edate").value &&!document.getElementById("date").value)
	{
		alert("Please be sure to enter a date range!")
	}
	if(document.getElementById("toc_r").checked == true || document.getElementById("toc_t").checked == true && !document.getElementById("edate").value)
	{
		alert("Please be sure to include an end date.")
	}
	if(document.getElementById("toc_r").checked == true || document.getElementById("toc_t").checked == true && !document.getElementById("date").value)
	{
		alert("Please be sure to include a start date.")
	}
}

Open in new window


Works fine. The problem is that if more than one criteria is met, the user has to click through several "alerts" in order to get back to the main screen.

How can I structure things so if one criteria is met that justifies an alert, the user user gets just that one alert and is allowed to view the main screen again?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
You could put a 'break' after each 'alert'.  I usually just collect the messages in a single string and alert on it at the end of the function.  If the string is empty, then there is no alert.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brucegustPHP DeveloperAuthor Commented:
Sorry, Dave...how do you do that? How do you put a "break" after each alert?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>How do you put a "break" after each alert?
just add a "return" after that, like:

function IsEmpty(){
	if(document.getElementById("toc_r").checked == false && document.getElementById("toc_t").checked == false && !document.getElementById("date").value &&!document.getElementById("edate").value)
	{
		alert("Please be sure to enter some kind of search criteria!");
                 return false;
	}
	if(document.getElementById("toc_r").checked == false && document.getElementById("toc_t").checked == false && document.getElementById("date").value)
	{
		alert("Please be sure to check either \"rank\" or \"trended.\"");
                 return false;
	}
	if(document.getElementById("toc_r").checked == false && document.getElementById("toc_t").checked == false && document.getElementById("edate").value)
	{
		alert("Please be sure to check either \"rank\" or \"trended.\"");
                 return false;
	}
	if(document.getElementById("toc_r").checked == true || document.getElementById("toc_t").checked == true && !document.getElementById("edate").value &&!document.getElementById("date").value)
	{
		alert("Please be sure to enter a date range!");
                 return false;
	}
	if(document.getElementById("toc_r").checked == true || document.getElementById("toc_t").checked == true && !document.getElementById("edate").value)
	{
		alert("Please be sure to include an end date.");
                 return false;
	}
	if(document.getElementById("toc_r").checked == true || document.getElementById("toc_t").checked == true && !document.getElementById("date").value)
	{
		alert("Please be sure to include a start date.");
                 return false;
	}
        return true;
}

                                

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.