javascript - jquery, append multiple values to one input hidden -


i have following variable

var $pk3s_c = $('<input id = query_form_tbl_info_'+query_index +'_pk3ss[] name =query_form[tbl_info]['+query_index+'][pk3ss][] type = hidden></input>'); 

and array

var pk3s = opts[tbl]["cols"]; 

during iteration through array, want append elements of array $pk3s_c

  $.each(pk3s, function(i,pk3){   $pk3s_c.attr('value',pk3);   }) 

the code above not working, shows me have appended last element of pk3s, , not of them. how can append each element of p3ks hidden input?

you aren't going array string field without converting string.

the json format very useful this

// convert array string var mystring = json.stringify(myarray);  // put string field it's value $('input').val(mystring); 

javascript can interpret resulting string , server side languages can convert string array value can understand (see php, ruby)

here an example in jsfiddle


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -