JQuery map() form inputs -


i'm mapping out name attributes of :input using example below. had put conditional statement in map() find out if checkbox checked , return true or false. i'm not getting select option name attr. feel it's taking more code writing should. efficient way name attributes , watch checked in checkboxes. check example @ http://jsfiddle.net/gvhaq/3/

<form>     <input type="text" name="name" value="john"/>     <input type="text" name="password" value="password"/>     <input type="text" name="url" value="http://domain.org/"/>     <select>         <option name="one">1</option>         <option name="two">2</option>         <option name="three">3</option>     </select>     <input type="checkbox"/>             </form> <p></p>  $("p").append($(":input").map(function() {     if ($(this).attr('type') == 'checkbox') {         return $(this).attr('checked');     }     else {         return $(this).attr('name');     } }).get().join(", ")); 

this being returned
name, password, url, , true

perhaps want?

$("p").append($(":input").map(function() {     if($(this).is('select')) {         return $(this).children('option').map(function() {           return $(this).attr('name');         }).get().join(", ");     } else if($(this).attr('type')=='checkbox') {         return $(this).attr('checked');     } else {         return $(this).attr('name');     } }).get().join(", ")); 

http://jsfiddle.net/gvhaq/4/

if not, should provide expected output is

edit: accepted version

$("p").append($(":input").map(function() {     if($(this).is('select')) {         return $(this).val();     } else if($(this).attr('type')=='checkbox') {         return $(this).attr('checked');     } else {         return $(this).attr('name');     } }).get().join(", ")); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -