1

I have 3 textboxes in a form - town, county and country. A list appears for town so the user can select from this list. When a town is selected I want the country and county textboxes to be populated. But when the town is selected, nothing appears in the other textboxes.

 function OnCheckIfTownValid<%= AddressType %>(result) {
        if(result.ID != -1){
            document.getElementById('<%= txtAddTownID.ClientID %>').value = result.ID;
            document.getElementById('<%= txtAddTown.ClientID %>').value = result.TownName;
            $('#<%= txtCountyID.ClientID %>').val(result.CountyID);
            $('#<%= txtCountryID.ClientID %>').val(result.CountryID);
            $('#<%= txtCounty.ClientID %>').val(result.County);
            $('#<%= txtCountry.ClientID %>').val(result.Country); 
        }
        else{
            document.getElementById('<%= txtAddTownID.ClientID %>').value = "0";
            document.getElementById('<%= txtAddTown.ClientID %>').value = "";
        }

Here is what console.log returns:

[object Object] {CountryID: 529, CountyID: 11852, CreatedBy: "", CreatedDate: date, Element: null, ID: 437, IsActive: true, ModifiedBy: "", ModifiedDate: date, TownISO: "0", TownName: "Aberdeen", Zone: ""}
   {
      [functions]: ,
      __proto__: { },
      __type: "Lookups+Town",
      CountryID: 529,
      CountyID: 11852,
      CreatedBy: "",
      CreatedDate: [date] Thu Aug 13 2015 17:13:53 GMT+0100 (GMT Daylight Time),
      Element: null,
      ID: 437,
      IsActive: true,
      ModifiedBy: "",
      ModifiedDate: [date] Thu Aug 13 2015 17:13:53 GMT+0100 (GMT Daylight Time),
      TownISO: "0",
      TownName: "Aberdeen",
      Zone: ""
   }
user123456789
  • 1,914
  • 7
  • 44
  • 100

1 Answers1

0

Got it!

Try this:

function OnCheckIfTownValid<%= AddressType %>(result) {
        if(result.ID != -1){
            document.getElementById('<%= txtAddTownID.ClientID %>').value = result["ID"];
            document.getElementById('<%= txtAddTown.ClientID %>').value = result["TownName"];
            $('#<%= txtCountyID.ClientID %>').val(result["CountyID"]);
            $('#<%= txtCountryID.ClientID %>').val(result["CountryID"]);
            $('#<%= txtCounty.ClientID %>').val(result["County"]);
            $('#<%= txtCountry.ClientID %>').val(result["Country"]);
        }
        else{
            document.getElementById('<%= txtAddTownID.ClientID %>').value = "0";
            document.getElementById('<%= txtAddTown.ClientID %>').value = "";
        }

You can also put a Console.Log(Result) in the function so you can see if result gets populated.

Edit: Link with more info: Link here

DieVeenman
  • 457
  • 1
  • 3
  • 18