php echo and jquery

Hello Experts,

I have a very small form to email (php script).
The form checks for missing fields such as name and email.

like so

if ($name == "") {
      echo "please fill in your name";
      exit;
      };

Open in new window


I created a div with an absolute position where i would like these messages to appear.
I trying to understand how to integrate jquery to help me show the relevant messages in the absolute positioned div.

can someone show me a quick example please?
RefaelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

uzzidesignCommented:
I presume that you want to use jQuery to control the behavior of the message, more than just the position? jQuery in this case would be good to use for hiding the validation messages until they are needed. The best thing to do is to use PHP or jQuery to add or remove classes on the div, and to use those classes as hooks to show/hide and style it with CSS depending on its state. You should do as much as possible with CSS and style on the div itself. You could store different types of messages (e.g., div.error, div.success) in PHP variables and have styles predefined for each class.

One simple method would be to have the div hidden with a display:none until the message appears:
 
if ($('div').is(':empty') {
	$(this).hide();   // toggles display:none
} else {
	$(this).show();   // toggles display:block
}

Open in new window

or a better practice:
if ($('div').is(':empty') {
	$(this).addClass('hidden');	
} else {
	$(this).removeClass('hidden');	
}

Open in new window


But you can get fancier with the jQueryUI library with stuff like dialog popups: http://jqueryui.com/demos/dialog/

Here's an example: http://jsfiddle.net/ChXbr/5/
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
RefaelAuthor Commented:
Thank you!
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
jQuery

From novice to tech pro — start learning today.