SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Populate a dropdown with text file and dynamically update the second drop down

    I have a situation here.

    I created two drop downs, where the second one dynamically updates according to first selection.

    Now I jus have 2 members in first drop down and 20 in second drop down. I hard coded using javascript. But by the end of this year the number increases to 100's, then we cannot hard code it.

    I use html,javascript,jsp for the webpage.

    Is there a way to populate the dropdowns with data in a text file where they can update the text file with new members.

    Please help me out and make my situation better!!!!

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    What data format will you want to be using for the text file?

    Something like JSON?

    Code javascript:
    [
        { id: 158377, name: 'Paul Wilkins' },
        { id: 430682, name: 'harshasrujan' }
    }

    Or perhaps native HTML, which makes some parts easier, but manipulating it harder.

    Code html4strict:
    <option value="158377">Paul Wilkins</option>
    <option value="430682">harshasrujan</option>

    If you use a different data format, have you considered how you will get that data in to javascript?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These are list of regions, bankers. Just Strings. There is no particular format for data. According to the solution I come up, they can provide the data in any required format.

    I am sorry, I dont what JSON is.

    Thanks for reply!!!!

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by harshasrujan View Post
    I am sorry, I dont what JSON is.
    JSON is JavaScript Object Notation.

    Basically you can read in JSON data from any kind of external source, and parse it to actual data.
    That way you can then loop through the array and then process it as actual data.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    JSON is JavaScript Object Notation.

    Basically you can read in JSON data from any kind of external source, and parse it to actual data.
    That way you can then loop through the array and then process it as actual data.
    Ok. what format the data should be in?

    How can we read the external source like text file?

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by harshasrujan View Post
    Ok. what format the data should be in?
    The format that it's in entirely depends on how it's going to be used.

    Quote Originally Posted by harshasrujan View Post
    How can we read the external source like text file?
    Have a look at the example code from the Bulletproof Ajax book.

    The chapter 3 code is a good simple example of the type of coding you would use to retrieve the contents of a text file.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •