Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Howto to get picklist values from many fields with JavaScript (from for-loop) ???

8 views
Skip to first unread message

Lollike

unread,
Nov 20, 2009, 8:31:40 AM11/20/09
to t...@dynamicsolutions.dk
I have many picklists on a form (a questionaire) in MsCRM 4.0.

The picklists would be something like this:
Value / Label
1 A little
2 More
3 A lot
(Default is nothing selected)

Each question is an attribute and the names are like this:
new_0101
new_0201
new_0301
new_0102
new_0202
and so on...

I would like to run through all the questions (fields) and sum up the
values representing the answers, but I can't figure out howto retrieve
the values, when I loop though the field names like my example
hereunder - please help...!

var i;
var t;
var fieldname;
var fieldvalue;

for (i=1; i<=75; i+
+) // 75
questions...
{
t = ((i<10) ? "0" : "") +
i; // If i>0 the put at
0 in front of i
fieldname = 'new_' + t +
'01'; // the field name could
then be fx "new_0102" or "new_0202" and so on
fieldvalue = document.getElementById('fieldname').Value; // Here's
my problem - I've tried many different versions of getElementBy... but
with no luck...
alert
(fieldvalue); //
just to monitor if I got the value or not...
// the math will come here - and is allready working if I manually
retrieve the field values in 75 single lines...
}

dave

unread,
Nov 20, 2009, 1:10:01 PM11/20/09
to

Hi,

There is just one bug in your code:

Should be:
fieldvalue = document.getElementById('fieldname').value;

instead of:


fieldvalue = document.getElementById('fieldname').Value;

"value" not "Value"

Regards,
Dawid Kołodziejczyk
http://team4crm.com

dave

unread,
Nov 20, 2009, 1:18:38 PM11/20/09
to

One more thing...
If you build field name dynamicly in variable "fieldname" you should
omit apostrophe in getElementById(). I should look like:

fieldvalue = document.getElementById(fieldname).value;

Regards,
Dawid Kolodziejczyk
http://team4crm.com

0 new messages