Ajax Updates

Ajax Updates


jQuery Column Filters

Posted: 09 Dec 2009 07:55 AM PST

This jQuery plugin for a quick way of allowing table columns to be filtered by the user. It will add text box’s to the top of each column in a table, by typing into the text box’s you can narrow the number of rows in the table down to those that match your search text. It allows for wild cards and a NOT operator (ie show me everything that doesn’t match my search text).

 $('#filterTable').columnFilters();  

To use this script you need to download jQuery (included in the download below). Each table you apply the script to must be well formed; containing atleast a tbody and a thead. The script doesn’t yet compensate for any cells that have a colspan greater than 1. Below are a list of the variables that can be changed and there defaults. Please also check out the demo!

* wildCard: (default ‘*’) Allow you to search for any characters. eg ‘*m’ or ‘*12*3′
* notCharacter: (default ‘!’) Allow you to NOT the results. eg ‘!T’ would return all rows that don’t start with ‘T’
* caseSensitive: (default ‘false’) Are results case sensitive.
* minSearchCharacters: (default ‘1′) The minimum amount of characters that each search string must contain before the filter is applied.
* excludeColumns: (default ‘[]‘) Which columns, if any, do not require a filter. This array is zero indexed. eg ‘[0,1]‘
* alternateRowClassNames: (default ‘[]‘) An array of alternating class names for each row in order to keep odd and even row styling on tables. Maximum of two items. eg ['rowa','rowb']
* underline (default ‘false’) Set to true if the script is to underline the search text whilst filtering is in progress… good for tables with lots of rows where the filter may take a second. (not in Opera)

One last thing, the row created containing the text box’s is given a class name of ‘filterColumns’ so that you may style that row using CSS.

Tested to work in the following browsers;

* IE 7 & 6
* FireFox 2.0.0.14
* Opera 9.24
* Safari for windows


Demo: http://www.tomcoote.co.uk/JavaScript/columnFilters/demo.html
Download: http://www.tomcoote.co.uk/Downloads/columnFilters.zip
Source: http://plugins.jquery.com/project/ColumnFilters

Related Listings:

  1. Multiple Filters Search using Adobe Spry The Spry framework for Ajax is a JavaScript library that...
  2. Checkbox filters with jQuery Script Perhaps I’m using delicious.com wrong, but sometimes I wish I...
  3. Tables with Style CSS It might not seem like it but styling tabular data...

Background Animation Plugin

Posted: 09 Dec 2009 07:50 AM PST

Adds the ability to do background-position animations to jQuery 1.2 and newer.
How to use:

  $('#background').animate({backgroundPosition: '10% 250px'}); 

Example:

  $('#background')    .click(function(){        $(this)             .animate({backgroundPosition: '500px 150px'})             .animate({backgroundPosition: '-20px 250px'})         ;    }); 

Known Issue

Due to a bug in FF 2.0, you have to set your (initial) background-position inline:

  <div style="background-position: 10px 20px"></div> 

Offcurse you can achieve this with JavaScript (jQuery), too:

 $('#background').css({backgroundPosition: '10px 20px'});  

If you don´t set the inline-Style the script will degrade gracefully in FF 2.


Demo: http://www.protofunc.com/scripts/jquery/backgroundPosition/
Download: http://plugins.jquery.com/files/jquery.backgroundPosition.js_7.txt
Source: http://www.protofunc.com/scripts/jquery/backgroundPosition/

Related Listings:

  1. Background Animation Script How to use: $('#background').animate({backgroundPosition: '(10% 250px)'}); Due to some browser...
  2. jAni – Jquery Animation for Background Images jAni is a simple plugin for jQuery which allows you...
  3. Ajax Manager : jQuery Plugin Ajax Manager helps you to manage AJAX requests and responses...

Mootools-Ajax Contact Form

Posted: 09 Dec 2009 07:48 AM PST

Ajax can be very intimidating if you know very little about Javascript. However, the good news about it is that AJAX is very popular and each day, more and more tools, applications, demos, tutorials and articles show up and we’re getting friendlier and friendlier with it. In this tutorial I am going to teach you how to create an Ajax contact form for your website. The main purpose of using ajax for this task will be the fact that you’re saving bandwith (hard to believe that in 2007 we’re still looking to save bandwith but…), it communicates with the visitor on the same page, almost instantly and is faster because you’re not loading another page to show a confirmation message or whatever else is supposed to show given the situations. There are many ways of doing this, we’re going to use mootools to make AJAX possible. Mootools is a lightweight javascript library developed by Valerio Proietti and is capable of creating a huge amount of effects. The advantage on mootools is that you don’t need to download the whole library just to have an ajax event or some other tiny effect. You just download what you need. Ok, now that we finished introducing our tools let’s start coding. Our small project will contain 4 files: mootools, a stylesheet and our index page (interface) which will be working with send.php with the help of ajax. Basically, we have our main page helped by some AJAX magic to send data and receive+display the response. Our php code will look like an ordinary PHP mailer, using the mail() function:

 < ?php 	error_reporting(E_NOTICE);  	function valid_email($str) 	{ 		return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; 	}  	if($_POST['first_name']!='' &amp;amp;amp;&amp;amp;amp; $_POST['last_name']!='' &amp;amp;amp;&amp;amp;amp; $_POST['e_mail']!='' &amp;amp;amp;&amp;amp;amp; valid_email($_POST['e_mail'])==TRUE &amp;amp;amp;&amp;amp;amp; strlen($_POST['message'])>30) 	{ 		$to = 'manilodisan@gmail.com'; 		$headers = 	'From: '.$_POST['e_mail'].'' "\r\n" . 				'Reply-To: '.$_POST['e_mail'].'' . "\r\n" . 				'X-Mailer: PHP/' . phpversion(); 		$subject = "Hello! I'm testing my new ajax email that I got from roscripts.com"; 		$message = htmlspecialchars($_POST['message']); 		if(mail($to, $subject, $message, $headers)) 		{//we show the good guy only in one case and the bad one for the rest. 			echo 'Thank you '.$_POST['first_name'].'. Your message was sent'; 		} 		else { 			echo "Message not sent. Please make sure you're not 				running this on localhost and also that you 				are allowed to run mail() function from your webserver"; 		} 	} 	else { 		echo 'Please make sure you filled all the required fields, 		that you entered a valid email and also that your message 		contains more then 30 characters.'; 	} ?>   

Analyzing the code you will notice the function (which was taken from our snippets section) “valid_email” that we will use to validate the email address of the visitor. Also, I’ve started the code using an if statement to make sure all fields are completed, the message is bigger then 30 characters (you can modify everything to match your needs) and that the sender’s email address is a valid one. Please notice that I used htmlspecialchars() to avoid any attempt of cross site scripting(XSS) which is hard to believe that will bypass any email client at this moment but it’s always good to be prepared and cover anything that might be vulnerable. The javascript code which will trigger the event and process our form is very small and easy to follow. It’s ready to run on domready which is way much faster than onLoad and it uses Fx.Elements to change the class of our receiver element (

) in order to show a loading gif until the job is done and our php sends back the response which can either be a positive one or negative.

window.addEvent('domready', function(){ 	$('myForm').addEvent('submit', function(e) {  	new Event(e).stop(); 	var log = $('log_res').empty().addClass('ajax-loading'); 	this.send({ 		update: log, 		onComplete: function() { 			log.removeClass('ajax-loading'); 		} 	}); 	}); });   



Demo: http://www.roscripts.com/uploads/articles/144/
Download: http://www.roscripts.com/attachments/download/144/8
Source: http://www.roscripts.com/AJAX_contact_form-144.html

Related Listings:

  1. Ajax Contact form with validation This form was inspired by Dustin Diaz’ original AJAX contact...
  2. Ajax Script – Contact Form This contact form is a fun example of together...
  3. Moo.Form Examples Script This page gives an overview of Ajax.Form object. It is...

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.