you'd likely find this a lot easier by  either using a database or array search

here's an example using JSON. All of the information is stored in JSON until needed and can be searched easily with $.each

http://jsbin.com/ohulu/edit

CreativeMind wrote:
Hi,
I need the ways to solve the problem.
scenario is: I have a dropdown and 4 textboxes, which are filled
through a callback function.
dropdown has multiple values. on selected index change of dropdown i
want to fill the text boxes with associated values. e.g
dropdown has list of countries.
when i select country, the four textboxes are filled with country's
four city names.
like if india  is selected , then textboxes should have delhi,
banglore,mumbai,hyderabad
if uk is selected, textboxes be filled with
london,bermingham,scotland.manchester.
if usa is selected then newyork,washington,pentagon,texas be in four
textboxes.

what i'm currently doing is:
-- in code below i'm appending the new dropdown options retrieved from
callback function, and also appending the associated cities in hidden
input types.

  var sourcedropdown = $(e.target).parent().parent().children(":nth-
child(7)").children().eq(0);

 $(sourcedropdown).append($('<option></option>').val(val).html
(sourcename).addClass('selectedval'+val));

var cityval=text[1];

$.each(cityval,function(leftval,rightval){
$(sourcedropdown).append("<input type=hidden id=hid"+leftval+"
value="+rightval+" >");

});
----
bydefault [select country] is added in dropdown with no associated
cities,
--
$(sourcedropdown).change(function(){
    // how can i get cities in textboxes
});
----
generated code of my above code is:

<select name="source" id="source0">
                  <option value="-1">Select country</option>

                <option value="0" >england</option><input
type="hidden" value="london" id="hid1"/><input type="hidden"
value="birmingham" id="hid2"/><input type="hidden" value="liverpool"
id="hid3"/><input type="hidden" value="leeds" id="hid4"/>

</select>
---
this is ok for one country but not ok for more than one country.. any
different way to associate cities with countries?

thanx

  

Reply via email to