Solved

php echo and jquery

Posted on 2012-04-03
2
411 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
2 Comments
 
LVL 6

Accepted Solution

by:
uzzidesign earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

820 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