I have some field names populated in the data element. I'm trying to form a query string with the field names and their corresponding values in the form for using in jquery ajax. The following code however, does not work for me.
$(".linkedfill").change(function(){
var params = $(this).data("select-params").split(",");
$.each(params, function(index,value){
pname = value.slice(value.IndexOf("["), value.IndexOf("]"));
pval = $(this).parents().find("[name='"+value+"']").val();
addparams = addparams + "&" + pname + "=" + pval;
});
});
The field name will be like header['fldname'] and the field is available somewhere in the same form. The data-select-params will be like data-select-params="header['fld1'],header['fld2']".
Update : My html for fields would look like this:
<input name='header[fld1]' />
<input name='header[fld2]' />
<select class='linkedfill' name='pselect' data-select-params="header[fld1],header[fld2]">
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
</select>
What am trying to do with jquery is get the values of header[fld1] & header[fld2] and form a query string out of the data.
Can anyone help me fix this? Thanks in advance.