I was working on a project which required a simple calendar with inline edit. The calendar is for a school which marks if the day is working or not, and the comment (told ya, its very simple). Needs PHP, jQuery, jQuery jEditable plugin and a MySQL table to store the data.

The demo is here. If anyone is interested in the code, drop a comment.

P.S: Yea I suck at CSS. If anyone does a better job, please let me know.

After my post about developing a new jQuery plugin, I’ve managed to shake off my apprehensions, and get it hosted on googlecode. The project is titled jGridTable, and hopefully isn’t already taken. I will dedicate a page to it in this blog, where I can keep track of day to day developments, invite comments and suggestions from people, and more importantly, ask for guidance. And if at all I get it to work, I intend to publish it with the liberal MIT license, so that others can keep improving it. My overall aim for the project is to make it as flexible as possible, without bloating up.

So here is to jGridTable. Lets see how far it goes.

After weeks of searching for the perfect grid based data editor for my project, I’ve aspired to build one myself. Sure there are hundreds of existing plugins and more which are well established, and developed by well knowledgeable folks, I find a few shortcomings. Drawing inspiration from the existing plugins, here are my goals:

Goals:

  • Uses jQuery library
  • Small and light. Size should be less than 30 KB for minified version
  • Dynamic data source for easy table population (JSON or plain HTML)
  • Create, Read, Update and Delete (CRUD) operation
  • Sorting based on columns (using tablesorter plugin)
  • Searching based on filters for multiple columns
  • Follows KISS Principal – Keep it simple stupid. No unnecessary insertion of DOM elements
  • Insertion of checkbox for each row and defining custom button to perform an action

What seems like a huge list of features add to my very basic problem : I’m still a noob at jQuery and javascript. So, as a personal goal this project is a way for me to learn jQuery right from scratch, and to put it to good use.

Methodology:

  • Study the existing plugins to understand how they work
  • Use code snippets that are already available. Reduces work, and will be much better than reinventing the wheel the wrong way
  • Less attention to appearance (CSS) till the code really works, partly because I’m still learning CSS, and would be tough to combine both jQuery and css code when I’m new to both.

As you’d have guessed, its an ambitious project for someone who is new to javascript/jQuery. Nevertheless, I hope I can pull it off with guidance from knowledgeable people who know their jQuery. I plan to host it on either github or google code and put up a dedicated page on this blog to keep track of the development. As the first step, I’ll start with defining the various functions that are required, thus creating a skeleton jQuery plugin, which simply displays a one line output when called in order (yea, I’m pathetic).

So anyone who reads this, please leave your thoughts, advice, comments here. Thank You.

This is a small tutorial/article on how to create a Mac OSX Finder like navigation page and to use it to list and download files that you have.  A screen shot below for people who do not know how it looks. It can be used as a simple yet elegant download script.

500px-osx_finder_columnview

Read more

One of the most mundane tasks in web development is insertion of forms into databases. Writing a query for each form is cumbersome and isn’t the best way to go about it. Now before I get started, there are “far better” ways of doing it like using datagrid, or form designers, etc. Since I don’t find them suitable for my taste, I’ve put together a very simple javascript that can do the job.

My example is based on PHP/MySQL and uses jQuery

The Problem: Generating an Insert Query for the particular form. Traditionally, if you form had say 25 fields, you’ll name them, and post/get them to a server side script like php. Then you have to get each field using the $_POST or $_GET variables, and generate the query. Imagine doing this for 25 fields! Hope you get the point.

The Solution: Automatically traverse the form, generate the query using javascript, then submit it to the server side script by Ajax POST using jQuery. The function takes 3 arguments: table name, success message, error message.

The Limitations: As you’d imagine, there are a few serious limitations:

  • The order of the form elements should match the order of the fields in the table. Needless to say the number of form elements should also match the number of fields in the table.
  • The database name is hard coded into the server side script. Since my work involves only a single database, I find it easier to keep things simple.

Steps:

1. In your normal HTML form, arrange the input boxes in the order that they appear in your database table. In this example, we have 3 text boxes: user, email and pass.

<div id=”container”>
<form id=”loginForm” method=”POST” action=”dbprocess.php”>
<dd>
<dl><label for=”user”>Username</label></dl>
<dt><input type=”text” name=”user” maxlength=”20″ /></dt>
</dd>
<dd>
<dl><label for=”email”>Email</label></dl>
<dt><input type=”text” name=”email” maxlength=”20″ /></dt>
</dd>
<dd>
<dl><label for=”pass”>Password</label></dl>
<dt><input type=”password” name=”pass” maxlength=”8″ /></dt>
</dd>
<input type=”submit” value=”Submit” id=”submitForm” />
</form>
</div>

2. Include the jQuery.js and formSubmit.js files in the header

3. Insert the following Javascript code that disables the submit button of the form, and calls our formSubmit function instead. The form submission is handled in the function via jQuery Ajax request.

<script type=”text/javascript>

$(document).ready(function(){
$(“#loginForm”).submit(function(){
return false;
});
$(“#submitForm”).click(function(){
formSubmit(“users”,”New user added successfully!”,”Error adding user!”);
});
});
</script>

4. Write your server side PHP script to connect to the database, and perform the operation

<?php
$query = stripslashes($_POST["query"]);

if(!$con = mysql_connect(“localhost”,”root”,”"))
die(“Database Connection Error”);

if(!mysql_select_db(“login”))
die(“Database does not exist”);

$result = mysql_query($query,$con);
if($result)
echo “1″;
else
echo mysql_error($con);
mysql_close($con);
?>

And that’s it! Your form insertion should be working provided you took care of the limitations. This script is useful if you have many forms with lots of input fields in your application. Comments, suggestions and criticisms welcome!

Download the script with example

    Stuff
    Everyone
    Calendar
    March 2010
    M T W T F S S
    « Jan    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
    Rate this blog
    Clickity
    15520
Get Adobe Flash playerPlugin by wpburn.com wordpress themes