Javascript

Modify Jquery Typing disable enter key / some key from start event

28 Aug , 2011  

I have chat applications based on NodeJS that using Jquery-typing for detecting user activity. This plugin is great, but i facing some problem with enter keys.

I make some script if user press “ENTER”, it will send message. But seems Jquery-typing detect “ENTER” key as start typing activity. It will make my chat application give stop typing notification into another users which message already send. I want to disable some keys in Jquery Typing.

So, i fork from original github and add-ed some additional feature called “keyClear”. Here are some implementation. “ENTER” keyCode is 13. So, i add it into keyclear options :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$('#text-input').typing({
    start: function (event, $elem) {
        if(checkVariable(now.name, now.roomId)){
            now.statusOnWriting();
        }
    },
    stop: function (event, $elem) {
        if(checkVariable(now.name, now.roomId)){
            now.statusOffWriting();
        }
    },
    keyclear: 13,
    delay: 1000
});

Now when people press “ENTER” it make not activity, not start or stop typing either.

You can clone it on : https://github.com/yodiaditya/jquery-typing.

,

configuration

How to remove upstream remote repository in Github

28 Aug , 2011  

When you forking repository, you usually add stream to enable push your changes into origin master. Adding stream to remote repository by :

1
git remote add upstream git://github.com/octocat/Spoon-Knife.git

But how to remove upstream if we use wrong github repository. Adding again will throw error “fatal: remote upstream already exists”, for example like this:

1
fatal: 'git//github.com/narfdotpl/jquery-typing.git' does not appear to be a git repository

To solve this problem, edit .git/config and remove upstream :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:yodiaditya/jquery-typing.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "upstream"]
        url = git://github.com/narfdotpl/jquery-typing.git
        fetch = +refs/heads/*:refs/remotes/upstream/*

Into

1
2
3
4
5
6
7
8
9
10
11
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:yodiaditya/jquery-typing.git
[branch "master"]
        remote = origin
        merge = refs/heads/master

Then you can add new upstream git agains. :)

,

configuration

Auto checking errors for Javascript in VIM using JavascriptLint

25 Aug , 2011  

I have edited a lot of javascript files in VIM. Checking errors in a lot of javascripts line is such a pain till i found JavasriptLint + VIM Plugin. Let get started, i use Ubuntu Natty 11.04 on this installation.

Updated!
You can fork it on Github :
Davepacheco’s javascriptlint Github

1. Install JavascriptLint

1
2
3
4
5
6
cd ~/
wget -c http://www.javascriptlint.com/download/jsl-0.3.0-src.tar.gz
tar -xvvf jsl-0.3.0-src.tar.gz
cd ~/jsl-0.3.0/src/
make -f Makefile.ref
sudo ln -s ~/jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl /usr/local/bin/jsl

2. Install JavascriptLint.vim

Download from http://www.vim.org/scripts/script.php?script_id=2578.

Or if youre using Vundle / Pathogen, then you can use this github :
http://github.com/joestelmach/javaScriptLint.vim.

Now, every you edit JS files, you will see error syntax checking windows in bottom of your VIM. Great tools!

,

configuration

Solving Snipmate vim error Snippet c) is already defined

23 Aug , 2011  

Today i get these errors after forking my github :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Warning in snipMate.vim: Snippet c) is already defined. See :h multi_snip for help on snippets with multiple matches.
Warning in snipMate.vim: Snippet date is already defined. See :h multi_snip for help on snippets with multiple matches.
Warning in snipMate.vim: Snippet ddate is already defined. See :h multi_snip for help on snippets with multiple matches

Warning in snipMate.vim: Snippet while is already defined. See :h multi_snip for
help on snippets with multiple matches.
Warning in snipMate.vim: Snippet r is already defined. See :h multi_snip for hel
p on snippets with multiple matches.
Warning in snipMate.vim: Snippet w is already defined. See :h multi_snip for hel
p on snippets with multiple matches.
Warning in snipMate.vim: Snippet rw is already defined. See :h multi_snip for he
lp on snippets with multiple matches.
Warning in snipMate.vim: Snippet defs is already defined. See :h multi_snip for
help on snippets with multiple matches.
Warning in snipMate.vim: Snippet defmm is already defined. See :h multi_snip for
help on snippets with multiple matches.
Warning in snipMate.vim: Snippet am is al

What the heck with this snipMate problem? Until i remember something :D

here are the solution :

delete snippets folder in bundle/snipmate.vim. This error happen because you already have another snipmate snippets in bundle folder. Just delete the default snippets in Snipmate.vim and all problems gone!

,

configuration

Hot tips collection about using VIM

21 Aug , 2011  

Today i try to learn VIM and found several trivial things that probably gain my effectivity about using VIM. Note that i use VIM for editing PHP, Python, Javascript, CSS and HTML. Also i create my own VIM like Netbeans ( Which it’s still my primary IDE for web development ) in http://github.com/yodiaditya/vim-netbeans. Here are hot tips :

How to indent visual blocks in VIM ?
After blocking using v, now press > for right indentation or < for indentation. Press . for repeat it's command if you think need to indent more. Fix indent width by put shiftwidth=2 or more in .vimrc.

For auto-indent, press ==

How to block one line in VIM ?
Using shift+v

How to paste with indentation included ?
After blocking code with v and y (for yanking / copy ), select your cursor to where the start aligning position. Then you can use ]p for paste text aligning indentation with surroundings

I will update this post as i found another tips.

,

php

How to solve tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 267] app/tmp/cache/persistent/ is not writable [CORE/cake/libs/cache/ file.php, line 267]

19 Aug , 2011  

Today i got this kind of error in my CakePHP 1.3. Here are the error code :

1
tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 267] app/tmp/cache/persistent/ is not writable [CORE/cake/libs/cache/ file.php, line 267]

I tried to solve this by chmod and change permisssion recursive into app/tmp.

1
2
cd app/
chmod 777 -R tmp

Hey, after change permission, it’s still give me error. What happen here? After walking around and analyze the error, i found the problem. It’s because i use file caching built-in CakePHP. So, i better disable it’s by editing app/config/core.php :

1
2
3
4
5
if($_SERVER['SERVER_NAME'] == 'localhost') {
   Configure::write('Cache.disable', true);
}else{
   Configure::write('Cache.disable', false);
}

This fixed my CakePHP in localhost. Now, time to works again and swipe another errors :)

,

configuration

How to learn and customized VIM like Netbeans for PHP + Python

13 Aug , 2011  

Today i start learning VIM which it takes me scracth my head overtime. Need a full 1 day to know that VIM actually is a powerfull text editor on the earth. Here are the reason why i and you should move into VIM rather using IDE editor :

1. VIM is widely used by many TOP developers around the world.
There so many great developer using VIM as default editor. Also, this editor became as standard in many insitution, big company and community. I heard that Googlers also using VIM with their custom configuration to editing and integrate with Google System.

2. VIM is text-editor that can be programmed.
For example, you need to edit Phyton files and press Shift+E to execute this file immediatelly. Which you can programmed Shift+E equal with command “/usr/bin/python your-script.py”. In another tabs, you need to do same thing, which Shift+e equal with “/usr/bin/php your-script.php”. You need text-editor that doing different service as based on the file extension.

Or maybe, you want to press F4 to commit this file into Github repo. It’s can be programmed as long as what you wanted to. You can make custom text editor based on your standard programming.

3. There only one editor that can match with VIM, called Netbeans. And yes, i still using Netbeans for editing some projects. And it’s still okay dude.

4. VIM is kind of investment. Just like you are PHP programmer that look Python is great language in the future. We need to invest them to be able catch up need in the future.

Being Technical.

When you start to learning VIM, i suggest to give one full day and use is as many time you have. Practice is one key to gain your skill on everything.

I use Ubuntu 11.04 and Macbook Pro here. So, what i share here is 100% working on Ubuntu.

I assume you’re newbies like me before knowing VIM. So, there are 2 things that you should know about VIM, that called .vimrc & .vim. This are located on your home directory ( ~/ ).

.vimrc is contain VIM configuration and .vim contain many plugins, syntax, documentation and many additional things that loaded by .vimrc when you opening VIM. So, start to search about .vimrc and .vim on Google.

Basic things to use VIM ( quotes not included ):

1. To editing file, press “i” or “Insert”
2. To back into command mode, press “CTRL+C” and press “:” for start execute command
3. To save, press “:w”
4. To save and quit, press “:wq”
5. When you see it’s meaning Backslash Button
6. Use “CTRL+F” for PAGE DOWN and “CTRL+B” for PAGE UP
7. In command mode, you can use UP and DOWN arrow to use same command before. Like in shell.

How to copy paste in VIM ?

1. Press “v” and using your arrow keys to block some text
2. Press “d” to cut or “y” for copy. Then press “p” to paste

How to search in VIM ?
1. Press “:/” and type what do you want to search. ex: :/hello
2. To next search, press “n”

How to execute this script on VIM ?
Use “:! %”. Example, execute this python script by “:!python %”

That’s for basic. Now, i am approaching how to make VIM like my Netbeans editor which it have autocomplete, file tree, tag / function list, auto indentation and many else!

Actually, i’m going crazy here. So, i start build my VIM. I suggest you to open vimrc and follow link and documentation there. It’s will helping you to customize VIM as what you want.
Here are some of my steps ( All explanation already in vimrc ) :

1. Editing .vimrc and make basic things.

1
2
3
4
5
6
7
8
9
syntax on " syntax highlighing
filetype on " try to detect filetypes
filetype plugin indent on " enable loading indent file for filetype
set number " Display line numbers
set numberwidth=1 " using only 1 column (and 1 space) while possible
set background=dark " We are using dark background in vim
set title " show title in console title bar
set wildmenu " Menu completion in command mode on
set wildmode=full " cycles between all matching choices.

2. NerdTree ( https://github.com/scrooloose/nerdtree )
After clone it, copy all files into ~/.vim by

1
cp -dR nerdtree/* ~/.vim/

To start using NerdTree, type :NERDTree in Vim. To move between windows, press “CTRL+w+w”

3. Pathogen
Why we should you Pathogen? Here is some cases. You have downloaded many plugins into VIM folder. In one day, some of your plugins updated. Then, what you should do? Deleting old files ? What happen if you delete wrong files?. Using Pathogen will ease our development which make each plugin run independently and updated from github.

Thank to https://github.com/tpope.

To install Pathogen :

1
2
3
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
&gt; ~/.vim/autoload/pathogen.vim

3. Snipmate
Is TextMate on VIM. I use Snipmate from Tpope as maintainer

1
2
3
4
% cd ~/.vim
% mkdir bundle
% cd bundle
% git clone git://github.com/garbas/vim-snipmate.git

# Install dependencies:
% git clone https://github.com/tomtom/tlib_vim.git
% git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
% git clone https://github.com/honza/snipmate-snippets.git

4. Installing Python Debugger like Pylint, Pyflakes and Pep8

1
2
3
sudo pip install pylint
sudo pip install pyflakes
sudo pip install pep8

For TLDR;
Go to https://github.com/yodiaditya/vim-netbeans and clone it!

,

wordpress

How to fix memcached problem in WordPress 3

10 Aug , 2011  

When using memcached plugin in WordPress 3 and multiple sites used same memcached server, all sites seems have wrong redirection. Thought it was my firefox cache problem but it doesn’t. This is because bug in object-cache.php. Mohanjit give solution for this problem by patching them.

Here are object-cache.php that you should put into wp-content :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<?php

/*
Name: Memcached
Description: Memcached backend for the WP Object Cache.
Version: 2.0
URI: http://dev.wp-plugins.org/browser/memcached/
Author: Ryan Boren


Install this file to wp-content/object-cache.php
*/

function wp_cache_add($key, $data, $flag = '', $expire = 0) {
    global $wp_object_cache;

    return $wp_object_cache->add($key, $data, $flag, $expire);
}

function wp_cache_incr($key, $n = 1, $flag = '') {
    global $wp_object_cache;

    return $wp_object_cache->incr($key, $n, $flag);
}

function wp_cache_decr($key, $n = 1, $flag = '') {
    global $wp_object_cache;

    return $wp_object_cache->decr($key, $n, $flag);
}

function wp_cache_close() {
    global $wp_object_cache;

    return $wp_object_cache->close();
}

function wp_cache_delete($id, $flag = '') {
    global $wp_object_cache;

    return $wp_object_cache->delete($id, $flag);
}

function wp_cache_flush() {
    global $wp_object_cache;

    return $wp_object_cache->flush();
}

function wp_cache_get($id, $flag = '') {
    global $wp_object_cache;

    return $wp_object_cache->get($id, $flag);
}

function wp_cache_init() {
    global $wp_object_cache;

    $wp_object_cache = new WP_Object_Cache();
}

function wp_cache_replace($key, $data, $flag = '', $expire = 0) {
    global $wp_object_cache;

    return $wp_object_cache->replace($key, $data, $flag, $expire);
}

function wp_cache_set($key, $data, $flag = '', $expire = 0) {
    global $wp_object_cache;

    if ( defined('WP_INSTALLING') == false )
        return $wp_object_cache->set($key, $data, $flag, $expire);
    else
        return true;
}

function wp_cache_add_global_groups( $groups ) {
    global $wp_object_cache;

    $wp_object_cache->add_global_groups($groups);
}

function wp_cache_add_non_persistent_groups( $groups ) {
    global $wp_object_cache;

    $wp_object_cache->add_non_persistent_groups($groups);
}

class WP_Object_Cache {
    var $global_groups = array ('users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss');

    var $no_mc_groups = array( 'comment', 'counts' );

    var $autoload_groups = array ('options');

    var $cache = array();
    var $mc = array();
    var $stats = array();
    var $group_ops = array();

    var $cache_enabled = true;
    var $default_expiration = 0;

    function add($id, $data, $group = 'default', $expire = 0) {
        $key = $this->key($id, $group);

        if ( in_array($group, $this->no_mc_groups) ) {
            $this->cache[$key] = $data;
            return true;
        }

        $mc =& $this->get_mc($group);
        $expire = ($expire == 0) ? $this->default_expiration : $expire;
        $result = $mc->add($key, $data, false, $expire);
        @ ++$this->stats['add'];
        $this->group_ops[$group][] = "add $id";

        if ( false !== $result )
            $this->cache[$key] = $data;
        return $result;
    }

    function add_global_groups($groups) {
        if ( ! is_array($groups) )
            $groups = (array) $groups;

        $this->global_groups = array_merge($this->global_groups, $groups);
        $this->global_groups = array_unique($this->global_groups);
    }

    function add_non_persistent_groups($groups) {
        if ( ! is_array($groups) )
            $groups = (array) $groups;

        $this->no_mc_groups = array_merge($this->no_mc_groups, $groups);
        $this->no_mc_groups = array_unique($this->no_mc_groups);
    }

    function incr($id, $n, $group) {
        $key = $this->key($id, $group);
        $mc =& $this->get_mc($group);

        return $mc->increment($key, $n);
    }

    function decr($id, $n, $group) {
        $key = $this->key($id, $group);
        $mc =& $this->get_mc($group);

        return $mc->decrement($key, $n);
    }

    function close() {

        foreach ( $this->mc as $bucket => $mc )
            $mc->close();
    }

    function delete($id, $group = 'default') {
        $key = $this->key($id, $group);

        if ( in_array($group, $this->no_mc_groups) ) {
            unset($this->cache[$key]);
            return true;
        }

        $mc =& $this->get_mc($group);

        $result = $mc->delete($key);

        @ ++$this->stats['delete'];
        $this->group_ops[$group][] = "delete $id";

        if ( false !== $result )
            unset($this->cache[$key]);

        return $result;
    }

    function flush() {
        return true;
    }

    function get($id, $group = 'default') {
        $key = $this->key($id, $group);
        $mc =& $this->get_mc($group);

        if ( isset($this->cache[$key]) )
            $value = $this->cache[$key];
        else if ( in_array($group, $this->no_mc_groups) )
            $value = false;
        else
            $value = $mc->get($key);

        @ ++$this->stats['get'];
        $this->group_ops[$group][] = "get $id";

        if ( NULL === $value )
            $value = false;

        $this->cache[$key] = $value;

        if ( 'checkthedatabaseplease' == $value )
            $value = false;

        return $value;
    }

    function get_multi( $groups ) {
    /*
    format: $get['group-name'] = array( 'key1', 'key2' );
    */
    $return = array();
        foreach ( $groups as $group => $ids ) {
            $mc =& $this->get_mc($group);
            foreach ( $ids as $id ) {
                $key = $this->key($id, $group);
                if ( isset($this->cache[$key]) ) {
                    $return[$key] = $this->cache[$key];
                    continue;
                } else if ( in_array($group, $this->no_mc_groups) ) {
                    $return[$key] = false;
                    continue;
                } else {
                    $return[$key] = $mc->get($key);
                }
            }
            if ( $to_get ) {
                $vals = $mc->get_multi( $to_get );
                $return = array_merge( $return, $vals );
            }
        }
        @ ++$this->stats['get_multi'];
        $this->group_ops[$group][] = "get_multi $id";
        $this->cache = array_merge( $this->cache, $return );
        return $return;
    }

    function key($key, $group) {
        global $blog_id;

        if ( empty($group) )
            $group = 'default';

        if (false !== array_search($group, $this->global_groups))
            $prefix = $blog_id;
        else
            $prefix = $blog_id . ':';

        return preg_replace('/s+/', '', "$prefix$group:$key");
    }

    function replace($id, $data, $group = 'default', $expire = 0) {
        $key = $this->key($id, $group);
        $expire = ($expire == 0) ? $this->default_expiration : $expire;
        $mc =& $this->get_mc($group);
        $result = $mc->replace($key, $data, false, $expire);
        if ( false !== $result )
            $this->cache[$key] = $data;
        return $result;
    }

    function set($id, $data, $group = 'default', $expire = 0) {
        $key = $this->key($id, $group);
        if ( isset($this->cache[$key]) && ('checkthedatabaseplease' == $this->cache[$key]) )
            return false;
        $this->cache[$key] = $data;

        if ( in_array($group, $this->no_mc_groups) )
            return true;

        $expire = ($expire == 0) ? $this->default_expiration : $expire;
        $mc =& $this->get_mc($group);
        $result = $mc->set($key, $data, false, $expire);

        return $result;
    }

    function colorize_debug_line($line) {
        $colors = array(
            'get' => 'green',
            'set' => 'purple',
            'add' => 'blue',
            'delete' => 'red');

        $cmd = substr($line, 0, strpos($line, ' '));

        $cmd2 = "<span style='color:{$colors[$cmd]}'>$cmd</span>";

        return $cmd2 . substr($line, strlen($cmd)) . "n";
    }

    function stats() {
        echo "<p>n";
        foreach ( $this->stats as $stat => $n ) {
            echo "<strong>$stat</strong> $n";
            echo "<br/>n";
        }
        echo "</p>n";
        echo "<h3>Memcached:</h3>";
        foreach ( $this->group_ops as $group => $ops ) {
            if ( !isset($_GET['debug_queries']) && 500 < count($ops) ) {
                $ops = array_slice( $ops, 0, 500 );
                echo "<big>Too many to show! <a href='" . add_query_arg( 'debug_queries', 'true' ) . "'>Show them anyway</a>.</big>n";
            }
            echo "<h4>$group commands</h4>";
            echo "<pre>n";
            $lines = array();
            foreach ( $ops as $op ) {
                $lines[] = $this->colorize_debug_line($op);
            }
            print_r($lines);
            echo "</pre>n";
        }

        if ( $this->debug )
            var_dump($this->memcache_debug);
    }

    function &get_mc($group) {
        if ( isset($this->mc[$group]) )
            return $this->mc[$group];
        return $this->mc['default'];
    }

    function failure_callback($host, $port) {
        //error_log("Connection failure for $host:$portn", 3, '/tmp/memcached.txt');
    }

    function WP_Object_Cache() {
        global $memcached_servers;

        if ( isset($memcached_servers) )
            $buckets = $memcached_servers;
        else
            $buckets = array('default' => array('127.0.0.1:11211'));

        foreach ( $buckets as $bucket => $servers) {
            $this->mc[$bucket] = new Memcache();
            foreach ( $servers as $server  ) {
                list ( $node, $port ) = explode(':', $server);
                $this->mc[$bucket]->addServer($node, $port, true, 1, 1, 15, true, array($this, 'failure_callback'));
                $this->mc[$bucket]->setCompressThreshold(20000, 0.2);
            }
        }
    }
}
?>

And put this on your wp-config :

1
2
3
4
5
global $memcached_servers;
$memcached_servers = array('default' => array('127.0.0.1:11211'));

global $blog_id;
$blog_id = 'your-domain-name-here';

,

configuration

Fixing Memcached Problem in Ubuntu Natty

8 Aug , 2011  

When restarting Memcached service, suddenly i got this kind of error :

1
2
3
4
5
6
7
8
Restarting memcached: perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
memcached.

After googling for a while, i got the solution is :

1
sudo apt-get install language-pack-en-base

Kudos to http://bookmarks.honewatson.com/2009/05/30/perl-warning-please-check-that-your-locale-settings-ubuntu/

,

Javascript

How to get select value using Jquery

6 Aug , 2011  

Simple things, we want to grab value from select button on Jquery. If you want to get option value of select list, use this :

1
$('select :selected').val();

If you want to get text value in select list, use this :

1
$('select :selected').text();

,

Javascript

Auto remember form input content while typing using JQUERY

6 Aug , 2011  

When clients inserting data into form, suddenly their connection lost or accidentally refreshed the web page. And guess what? they facing new empty form again and feel tired to inserting same data again. We can reduce this by using JQUERY cookies which can remember what clients type into form. So, when they refreshed pages even close and open it again, they have previous input data.

To do this, you must download Jquery & Jquery Cookies.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<script type="text/javascript">

    function remember( selector ){
        $(selector).each(
                function(){
                    //if this item has been cookied, restore it
                    var name = $(this).attr('name');
                    if( $.cookie( name ) ){
                        $(this).val( $.cookie(name) );
                    }
                    //assign a change function to the item to cookie it
                    $(this).change(
                    function(){
                        $.cookie(name, $(this).val(), { path: '/', expires: 1 });
                    }
                );
            }
        );
    }

    $(document).ready(function(){

       $(function() {
            remember('[name=website]');
        })

        $('#region a').click(function(){
            var newValue = $('#OodleSearch').val() + ' ' +$(this).text();
            $('#OodleSearch').attr('value',newValue);
        })

    })
</script>

Now if you have input form with name attribute is “website” :

1
<input type="text" name="website" />

Then, now it’s auto remembering.

Kudos to : http://www.komodomedia.com/blog/2008/07/using-jquery-to-save-form-details/

,