Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8565977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:33:06+00:00 2026-06-11T17:33:06+00:00

Scenario I have a input box for post codes. When you put in a

  • 0

Scenario

I have a input box for post codes. When you put in a postcode it makes a call to a web service and gets all the suburb names back and binds them to a list, like an input dropdown list.

This works when I return a List<string> from the web service for just the names. No problem.

The problem arises when I go to save the values to the db. When it gets saved I cannot save the name of the suburb in the suburb column in the db. I have to save the id of that suburb for the foreign key constraint.

So then I changed the List<> thing slighty and cheated and returned the following.

<ArrayOfString>
<string>8213</string>
<string>BROOKFIELD</string>
<string>8214</string>
<string>CHAPEL HILL</string>
<string>8215</string>
<string>FIG TREE POCKET</string>

etc….

The reason for this is so I can have the value of the item in the drop down as the id and hence can save that in the code behind on save.

To do this, I did the following:

$(result).each(function (index, value) {

            var suburbname;

            var pattern = new RegExp('[0-9*]');
            var m = pattern.exec(value);

            if (m == null) {
                suburbname = value

                var o = new Option(suburbname, suburbid);
                /// jquerify the DOM object 'o' so we can use the html method
                $(o).html(suburbname);
                $(document.getElementById('<%= suburb.ClientID %>')).append($("<option></option>")
                                                                .attr("value", suburbid)
                                                                .text(suburbname));

            }
            else {
                suburbid = value
            }

That works as well… the drop down only has name and the value for those is the number

The problem….?

I am making assumptions above which I don’t like… I.e. that the name never has a number it, that the web service will always return the id first to set the id before running the add to the dropdown for the first time. It just feels wrong…. :S (thoughts?)

So, if I change the web service to return a datatable, to out the following (which is what the whole query returns):

<Suburbs diffgr:id="Suburbs1" msdata:rowOrder="0">
<SuburbID>8213</SuburbID>
<SuburbName>BROOKFIELD</SuburbName>
<StateID>4</StateID>
<StateCode>07</StateCode>
<CountryCode>61</CountryCode>
<TimeZones>10.00</TimeZones>
<Postcode>4069</Postcode>
</Suburbs>

Is there a way of acheiving the same as above in js/jquery. So when the user inputs the postcode the webservice returns the datatable and then binds it to the select with the SuburbID going into the value and the name going into the text???

Any other ways I could return the data from the web service to solve this?

Note: essentially I need the option to look like this:

<option value="8213">BROOKFIELD</option>

I also thought I could make a second call to get just the id on the bind of the text… but I kind of want to only make one call….

Thanks in adance,

Cheers
Robin

.net, C#, js, jquery, web service…..

Solution with guidance from Billy

The adding to the select using the other method below did not work, but my original way did once I had the correct variables so just used that….

The service returns:

<ArrayOfMyClass>
<MyClass>
<ID>8213</ID>
<Name>BROOKFIELD</Name>
</MyClass>

… etc

The js is: (note: it is onchange of the postcode input box. it runs a web service and then on success runs the following)

function OnCompleted(result) {

        var _suburbs = result;
        var i = 0;

        $(_suburbs).each(function () {
            var SuburbName = _suburbs[i].Name;
            var SuburbID = _suburbs[i].ID;

            $(document.getElementById('<%= suburb.ClientID %>')).append($("<option></option>")
                                                               .attr("value", SuburbID)
                                                                .text(SuburbName));
            i = i + 1;
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:33:08+00:00Added an answer on June 11, 2026 at 5:33 pm

    You can get your webservice to return that (or any subset that contains at least the id and the name) :

    <Suburbs diffgr:id="Suburbs1" msdata:rowOrder="0">
    <SuburbID>8213</SuburbID>
    <SuburbName>BROOKFIELD</SuburbName>
    <StateID>4</StateID>
    <StateCode>07</StateCode>
    <CountryCode>61</CountryCode>
    <TimeZones>10.00</TimeZones>
    <Postcode>4069</Postcode>
    </Suburbs>
    

    Than use your javascript foreach like such :

    var root = $('#<%= suburb.ClientID %>');
    
    $(result).each(function (index, value) {
    
        var row = $(value)[0];
    
        $('<option></option>')
            .attr('value', $('SuburbID', row).text())
            .text($('SuburbName', row).text())
            .appendTo(root);
    }​);
    

    EDIT : here is a jsfiddle : http://jsfiddle.net/rRqJa/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SCENARIO I have to access a web service with a .NET client. The service
Scenario: i have a web form from where i m taking input for Item
In a pretty typical scenario, I have a 'Search' text box on my web
In my scenario, I have a program that analyzes data input files and produces
Scenario: I have to check for user input (a string) that shouldn't contain <.%?/
Here's the scenario: I have a textbox and a button on a web page.
I have scenario, Page contains Check in date and Check out date for input.
Scenerio: I have some divs populated through foreach loop like below <div id=div1><input type=hidden
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Scenario: I have a console application that needs to access a network share with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.