Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php echo and jquery

Posted on 2012-04-03
2
Medium Priority
?
437 Views
Last Modified: 2012-04-08
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?
0
Comment
Question by:Refael
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
uzzidesign earned 2000 total points
ID: 37803495
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
 

Author Closing Comment

by:Refael
ID: 37821868
Thank you!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question