Created
June 19, 2012 17:14
-
-
Save kopiro/2955360 to your computer and use it in GitHub Desktop.
Autocomplete Forms (test)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fields = { | |
'nome':'Flavio', | |
'cognome':'De Stefano', | |
'sesso':'m', | |
'e-mail':'[email protected]', | |
'email':'[email protected]' | |
}; | |
function sortfunction(a, b) | |
{ | |
return (a.c < b.c); | |
} | |
var liked = function(t) | |
{ | |
console.log('LIKED:', t); | |
var matches = []; | |
for (var k in fields) | |
{ | |
var c = t.match( new RegExp(k, 'i') ); | |
if (c) | |
{ | |
var r = fields[k]; | |
if (r) | |
matches.push({ r:r, c:c[0].length }); | |
} | |
} | |
if (matches) | |
{ | |
matches = matches.sort(sortfunction); | |
if (matches[0]) return matches[0].r; | |
} | |
} | |
var go = function() | |
{ | |
$('form input[type=text]:visible, form input[type=email]:visible').each(function(k,v) | |
{ | |
var label = $('form label')[k]; | |
var labeltext = $(label).text(); | |
var toi = liked(labeltext); | |
console.log('TOI', toi); | |
$(v).val( toi ) | |
}); | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment