Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to combine all value from jquery.each function

Look at my code, I am trying to combine all value from the jquery.each to a string like this ok,good, and then passed to ajax value. Appreciate. or array('ok','good') acceptable also

var global = {
    "44":["onset","frequency"],
    "45":["onset"]
};
var $val = global[44];
            
jQuery.each( $val, function( key ,value) {		
    var value = $('#'+value).val();			
});
var $combine = ;//not sure how to combine all value like this (ok,good), or array(ok,good) acceptable also
var data= {
    action: 'check_first',
    AjaxFrontNonce : ajax_csky.AjaxFrontNonce,
    combine : $combine
}
<input type="hidden" id="onset" value="ok">
<input type="hidden" id="frequency" value="good">
like image 557
conan Avatar asked Dec 06 '25 06:12

conan


1 Answers

Try this working snippet

var global = {
  "44": ["onset", "frequency"],
  "45": ["onset"]
};
var $val = global[44];
var arr = [];
$.each($val, function(key, val) {
  var value = $('#' + val).val();
  arr.push(value);
});

var $combine = arr; //not sure how to combine all value like this (ok,good), or array(ok,good) acceptable also
console.log($combine);
var data = {
  action: 'check_first',
  //AjaxFrontNonce : ajax_csky.AjaxFrontNonce, not defiend
  combine: $combine
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" id="onset" value="ok">
<input type="hidden" id="frequency" value="good">
like image 181
cheralathan Avatar answered Dec 07 '25 19:12

cheralathan