You are viewing limited content. For full access, please sign in.

Question

Question

Forms - Javascript accessing drop down in a collection

asked on November 11, 2015

When in he Javascript editor it shows all fields in the collection as having the same ID, "q3". However Chrome shows the actual IDs to be Field3(1), Field3(2) etc.

When I access a drop down using q3 it works correctly  but  accesses all fields within the drop down.

var target = $('#q3 select');

When I try to access them individually it does not work. Is there another ID for the individual fields?

var target = $('#Field3(1) select');

 

0 0

Replies

replied on November 12, 2015

Hi Chad,

It seems strange that you can't select it like that, I just tested on my system too and for whatever reason it doesn't work. However you could try using this:

var target = $("#q42 select").eq(1);

The above will grab the second dropdown in the collection as .eq() starts from 0 and cycles through all elements that match the selector you choose. It then stops when it gets to the number you choose with the .eq() function.

Hope this is helpful!

Dan

0 0
replied on November 12, 2015

The difference is in where the ID is that you are selecting. With the regular field "#q3" this ID is actually assigned to a <li> element in the HTML that is a parent of the <select> element you are trying to access. This is why you have the space in your selector: "#q3 select". The "FieldN(X)" IDs are directly assigned to the <select> elements, so you don't need that in your selector. Try just using:

var target = $("#Field3(1)")

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.