CSS & Web Design Forum  

Welcome to the CSS & Web Design Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
WM Media Banner

Supporters
Pos Software - POS hardware and Software to track, control and manage your inventory.
Web Templates - BoxedArt is the most reliable source for unlimited template downloads.

Directory Submission
WL Marketing - Your #1 source for building links

Go Back   CSS & Web Design Forum > Web Design > AJAX, Javascript & DOM
Reply
 
Thread Tools Search this Thread Display Modes
(#1)
Old
Geoff Cox
Guest
 
Default how to create params({ .. }) ? - 05-30-2009, 12:53 PM

Hello,

As part of Ajax I have

var params = ({
mysql_c21answer:c2[1],
mysql_c21correctanswer: correct_answerc2[1],
mysql_c22answer:c2[2],
mysql_c22correctanswer: correct_answerc2[2]
});

but want to create params using a loop like

var details = "";
for (var i = 0; i < 2; ++i) {
var nr = i + 1;
details += "mysql_c2" + nr + "answer:"
+ c2[nr] + ",\n"
+ "mysql_c2" + nr + "correctanswer:"
+ correct_answerc2[nr] + ",\n"
}

now the loop does create the contents as shown inside var params etc
but how do I use the details string to create params correctly?

var params = ({ etc ]); is creating an array or is there more to it
that I am missing?

Thanks

Geoff
Reply With Quote
(#2)
Old
JR
Guest
 
Default Re: how to create params({ .. }) ? - 05-30-2009, 12:53 PM

Hi,
If I'm not mistaken, you need to create an object (params), don't you?
And supposing c2 and correct_answerc2 are arrays created somewhere in
your code before loop, then:

var params = {}, i = 0;
while (i < 2) {
++i;
params["mysql_c2" + i + "answer"] = "c2[" + i +"]";
params["mysql_c2" + i + "correctanswer"] = "correct_answerc2["+ i
+"]";
}

Joao Rodrigues
Reply With Quote
(#3)
Old
Geoff Cox
Guest
 
Default Re: how to create params({ .. }) ? - 05-30-2009, 01:14 PM

On Sat, 30 May 2009 05:22:03 -0700 (PDT), JR
<groups_jr-1@yahoo.com.br> wrote:

>Hi,
>If I'm not mistaken, you need to create an object (params), don't you?
>And supposing c2 and correct_answerc2 are arrays created somewhere in
>your code before loop, then:
>
>var params = {}, i = 0;
>while (i < 2) {
> ++i;
> params["mysql_c2" + i + "answer"] = "c2[" + i +"]";
> params["mysql_c2" + i + "correctanswer"] = "correct_answerc2["+ i
>+"]";
>}
>
>Joao Rodrigues


Many thanks Joao - just the ticket!

Cheers

Geoff
Reply With Quote
(#4)
Old
RobG
Guest
 
Default Re: how to create params({ .. }) ? - 05-31-2009, 12:23 AM

On May 30, 11:11*pm, Geoff Cox <g...@freeuk.com> wrote:
> On Sat, 30 May 2009 05:22:03 -0700 (PDT), JR
>
> <groups_j...@yahoo.com.br> wrote:
> >Hi,
> >If I'm not mistaken, you need to create an object (params), don't you?
> >And supposing c2 and correct_answerc2 are arrays created somewhere in
> >your code before loop, then:

>
> >var params = {}, i = 0;
> >while (i < 2) {
> > *++i;
> > *params["mysql_c2" + i + "answer"] = "c2[" + i +"]";
> > *params["mysql_c2" + i + "correctanswer"] = "correct_answerc2["+ i
> >+"]";
> >}

>
> >Joao Rodrigues

>
> Many thanks Joao - just the ticket!


Incidentally, square bracket notation is covered in the FAQ and notes:

<url: http://www.jibbering.com/faq/#propertyAccessAgain >


--
Rob
Reply With Quote
(#5)
Old
Geoff Cox
Guest
 
Default Re: how to create params({ .. }) ? - 05-31-2009, 04:35 PM

On Sat, 30 May 2009 17:16:56 -0700 (PDT), RobG <rgqld@iinet.net.au>
wrote:

>On May 30, 11:11*pm, Geoff Cox <g...@freeuk.com> wrote:
>> On Sat, 30 May 2009 05:22:03 -0700 (PDT), JR
>>
>> <groups_j...@yahoo.com.br> wrote:
>> >Hi,
>> >If I'm not mistaken, you need to create an object (params), don't you?
>> >And supposing c2 and correct_answerc2 are arrays created somewhere in
>> >your code before loop, then:

>>
>> >var params = {}, i = 0;
>> >while (i < 2) {
>> > *++i;
>> > *params["mysql_c2" + i + "answer"] = "c2[" + i +"]";
>> > *params["mysql_c2" + i + "correctanswer"] = "correct_answerc2["+ i
>> >+"]";
>> >}

>>
>> >Joao Rodrigues

>>
>> Many thanks Joao - just the ticket!

>
>Incidentally, square bracket notation is covered in the FAQ and notes:
>
><url: http://www.jibbering.com/faq/#propertyAccessAgain >


thanks Rob,

Cheers

Geoff
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Hosting at Triple.com
vBulletin Skin developed by: vBStyles.com

Printing Company  Link Building Services