ajax - Auto-populating a list box of country names using jquery and the box's click event -
In my form there is a list box that demands the user's country but I can only list box through an AJAX call I want to populate, if the box does not already show the user's country, initially there is only one country in the list box - the country has returned to see the country of IP-to-country.
It seems that the default action of the list box occurs before my event action. I want to do my first action so that when the user clicks on the list box, the box is already populated, since the servers are closed before the box opens.
Thanks for any suggestions
$ (). Ready (function () {$ ('select # selCountry'). ('Click', function () {var selCountry = $ (select 'selCountry'); selected = $ (selCountry) .val (); selCountry .html ('& lt; Option value = "" & gt; ... Loading ... / options & gt;'); $ .getJSON ('/ AjaxHelpers / CountryList', function (data) {if (Data.length) {var option = ''; (Val I = 0; I & lt; data.length; i ++) {var key = data [i] .key; on Val = data [I] Option; option + = '& lt; option value = "' + + key +"; if (key == selected) {options = = selected = "selected" ';} options + =' & gt; '+ Val + '& lt; / option & gt;';} selCountry.html (option);} other {selCountry.html ('& lt;
HTML:
Pre> & lt; div & gt; select id = "sel country" name = "country code" & gt; option value = "GB" & gt; United Kingdom & lt; / option & Gt;
You will not have any joy cross browser Click on the event to only support the change event, so you have to reconsider.
One option would be to use the labels shown to the IP country and if the user wants to change it then they click on the button next to the label that creates & amp; Selects the selection and changes the label.
Comments
Post a Comment