SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Refresh values in Select List based onChange of a Dropdown box

    Hello all

    I am trying to learn and use good DHTML concepts and code (assuming they are needed). My current issue concerns how to handle this situation.

    I have a Select List box which displays values based on what value is selected in a dropdown list. For example, my dropdown list contains a class name, and the Select list contains all of the students who are registered for that class.

    So what I would like to occur, is when the user changes the class from the dropdown box, the Select List is re-created displaying the students who are enrolled in that class.

    I thought I could do this without having to reload the page (with DHTML) but here is my problem.

    I use the ASP code to select the students for the class. When the page initially loads, I just take the primary key from the 1st class and display all of the students for that class. Now once the page loads, I can not re-query unless I reload the page correct?

    I guess I saw a few ways I could handle this…

    1) I could learn AJAX (make an ASP call and then rebuild the list box using DHTML)… do you think this is possible?

    2) Initially when the page is loaded, I could select all students and place them in a large array. Then when the user changes the class dropdown, I could use JavaScript to spin through all of the values to rebuild the Select List but I don’t think this approach is very efficient.

    3) I guess I could also just forget about the DHTML and place the class id value in session and just reload the page.

    I was hoping someone could advise me on the best way to handle this situation. Maybe I have not considered the correct solution.

    Thanks in advance for your time.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep those are your options in a nutshell. All are possible and viable depending on a few conditions.

    To determine the right option, consider...
    - how often will that page be visited? If lots and lots, a client-side solution would relieve load from the server.
    - how many students are we talking about? If thousands, then loading that array every page load would take a long time.
    - are browsers with javascript turned off / without ajax support a concern? If so then you have to do it server-side.

    Personally I'd say ajax is the way to go.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your feedback.

    There are not a lot of students in the list... maybe 25 each and there are currently about 5 to 10 classes.


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
  •