Jquery - Change dynamic dropdown selected element -


I have a dynamically generated dropdown for which I need to change the selected value using Jquery.

  & lt; Selection class = "txtfield country" id = "ctl00_MainContentAreaPlaceHolder_personalInformation_country" name = "ctl00 $ MainContentAreaPlaceHolder $ personalInformation $ country" & gt; & Lt; Option value = "FJ" & gt; FIDJI & lt; / Option & gt; & Lt; Option value = "FI" & gt; Finland & lt; / Options & gt; & Lt; Option value = "FR" selected = "selected" & gt; France Metropolitan & lt; / Options & gt; & Lt; Option value = "GA" & gt; GABON & lt; / Options & gt; & Lt; / Select & gt;  

There is a way to use full idle (ctl00 includng ..):

  $ Jay ("# ​​ctl00_MainContentAreaPlaceHolder_DeliveryPersonalInformation_country Option [Value = 'Fr'] "). Ether ('selected', 'selected');  

Is there a way to use CSS? Can I find the element and change the value because I like not using dynamic control ID?

Edit:

I forgot to mention that I have 2 custom controls on the same dropdown page.

Therefore generates custom control 1:

  & lt; Select class = "txtfield ckgcountry" id = "ctl00_MainContentAreaPlaceHolder_personalInformation_country" name = "ctl00 $ MainContentAreaPlaceHolder $ personalInformation $ country" & gt; ... & lt; Option value = "ZW" & gt; ZIMBABWE & lt; / Options & gt; & Lt; / Select & gt;  

and generates Customer Control 2:

  & lt; Selection class = "txtfield country" id = "ctl00_MainContentAreaPlaceHolder_personalInformation_country" name = "ctl00 $ MainContentAreaPlaceHolder $ personalInformation $ country" & gt; & Lt; Option value = "FJ" & gt; FIDJI & lt; / Option & gt; & Lt; Option value = "FI" & gt; Finland & lt; / Options & gt; & Lt; Option value = "FR" selected = "selected" & gt; France Metropolitan & lt; / Options & gt; & Lt; Option value = "GA" & gt; GABON & lt; / Options & gt; & Lt; / Select & gt;  

By using the code it only changes the value of the first name that it finds in the DOM, how do I change the value of the second ... One way to do this is to use CSS Experiment?

It seems that you are using ASP.NET.

This is not really reliable to use full ASP.NET control ID (post-render) because it can change at any point. The only part of the id that is not changed is the last part of the ID that was defined in the ID property of ASP.Net control.

Select that item from that wildcard selector

// Select the current selected item $ ("[ID $ = 'Personal Notice'] option: Selected"). RemoveAttr ("Selected"); // Choose an option on index 0 $ ("[id $ = 'select personal information'] Option: one (0)"). Ether ("selected", "selected"); Select option with

or

  // value to select FR $ ("[id $ = 'personalInformation_country'] option [value = 'FR'] ") .attr (" selected "" selected ");  

$ = 'personalInformation_country' will end with all the id "personalInformation_country", which should be only one!


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -