Created
February 29, 2012 10:21
-
-
Save mpociot/1939656 to your computer and use it in GitHub Desktop.
form validation
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
for( var key in req ){ | |
var value = req[key]; | |
$('input[type="text"][name="'+key+'"]').val(value); | |
$('input[type="checkbox"][name^="'+key+'"]').removeAttr('checked'); | |
$('input[type="checkbox"][name="'+key+'"][value="'+value+'"]').attr('checked','checked'); | |
if( typeof value === 'object' ){ | |
for(var i=0;i<value.length;i++){ | |
var check = value[i]; | |
$('input[type="checkbox"][name^="'+key+'"][value="'+check+'"]').attr('checked','checked'); | |
} | |
} | |
$('select[name="'+key+'"] option').removeAttr('selected').filter('[value="'+value+'"]').attr('selected','selected'); | |
$('textarea[name="'+key+'"]').val(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment