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

$("#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;
		})

Open in new window

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
The problem is not a closing ')' it is your quotes. You are putting unopened / closed quotes around object references.

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
for (i=0; i<vals.length;i++){
  str += '&' + 
    $('#' + i.name) + 
    '_title=' + 
    $('#' + i.name').attr('title') + 
    '&' + 
    $('##' + i.name) + 
    '_alt=' + 
    $('##' + i.name').attr('alt');
}

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
for (i=0; i<vals.length;i++){
  str += '&' + 
    $('#' + i.name) + 
    '_title=' + $('#' + i.name).attr('title') + 
    '&' + 
    $('##' + i.name) + 
    '_alt=' + 
    $('##' + i.name).attr('alt');
}

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.
1
erikTsomikSystem Architect, CF programmer Author Commented:
the string should have the format {name: value,name: value}
0
erikTsomikSystem Architect, CF programmer Author Commented:
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}});

Open in new window

0
Julian HansenCommented:
so you want to create a JSON string?

Then simply do this
var vals  = JSON.stringify($("#frm2").serializeArray());

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erikTsomikSystem Architect, CF programmer Author Commented:
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"}]

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.