erikTsomik
asked on
pass form variable
I need to pass params to the coldfusion cfc using Bootstrap table toolbar.
When I click the apply button I am serializing the form into array and now I need to split the variable. I have the code bu I get the error message Uncaught SyntaxError: missing ) after argument list
When I click the apply button I am serializing the form into array and now I need to split the variable. I have the code bu I get the error message Uncaught SyntaxError: missing ) after argument list
$("#btnApply").click(function(){
//alert($("#frm2").serialize());
var vals = $("#frm2").serializeArray();
var str = "";
for (i=0; i<vals.length;i++){
str += '&' + $('#' + i.name) + '_title=' + $('#' + i.name').attr('title') + '&' + $('##' + i.name) + '_alt=' + $('##' + i.name').attr('alt');
}
alert(str);
$('#classes').bootstrapTable('refresh',{query: {str}});
return false;
})
ASKER
the string should have the format {name: value,name: value}
ASKER
So I did this and it is kind of working. but the result get passed as result[locationState]:MD and I need locationState: MD
var result = { };
$.each($('form').serializeArray(), function() {
result[this.name] = this.value;
});
$('#classes').bootstrapTable('refresh',{query: {result}});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Julian Hansen: I try that but does not work. I need the items listed individually
order: asc
limit: 20
offset: 0
vals: [{"name":"output","value":""},{"name":"fromDate","value":""},{"name":"toDate","value":""},{"name":"locationState","value":""},{"name":"leaseStatus","value":"0"},{"name":"leaseStatus","value":"1"},{"name":"leaseStatus","value":"2"},{"name":"isPaid","value":"0"}]
A bit of advice to keeping bugs down - make your code clean and easy to read. One long line of concatenation is asking for trouble
Let's reformat your code and we should see the errors immediately
Open in new window
What immediately jumps out here is the $('#' + i.name').attr on line 5 - you have a closing \' that should not be there.The same applies on the second last line.
Fixing those you get
Open in new window
Which should be error free but will it do what you want?Let's look at the for loop. You are iterating over a variable i - which is an integer - however throughout your loop you refer to i.name - that simply is wrong.
You need to fix that first. I have no idea what you meant to do so I can't correct it.
Then some other things that popped up
$('#' + i.name) - what are you expecting this to do (line 3)? That is a jQuery function that returns a jQuery object. The result of that concatenation will be [object, object].
Finally you have $('##' + i.name) - what are you hoping that is going to do?
I think what you need to do here is explain to us what it is you are trying to create in the for loop. Tell us where the information comes from and then let's see if we can make it do what you want.