SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2005
    Location
    N-472'26" W-12249'34"
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Set a dropdown value to selected based on another dropdown selection

    sorry if this is a repeat, but I didn't see anything like it, it's a bit complex to search for.

    Here's my problem:

    I have a select box that can contain multiple rows, with each row containing a client ID, dates, and a service code that they're billing for.

    I have the values for all of these pulling and splitting just fine, and the ones that populate text boxes work great, but the billing code is chosen from another select box and I need to update the selected option to be the one returned from the main selection.

    i.e. the screen loads with blank fields and the first option showing in the billing code selection box. The user then selects an old record to update from the main display and all of the blank text boxes are filled, how do I make the right code be selected in the billing code drop-down?

    I can include code here for anything if people want to see it, but everything I have works, it's just updating this second drop-down when the first is changed.

    And I don't want to add-remove values, they're already set by a SQL database call to the valid values.

    Thanks so much for any help!
    -J

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2005
    Location
    N-472'26" W-12249'34"
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Found a solution, of sorts.

    I don't love this, it's not elegant, but it gets it done and keeps me on schedule.

    In case this helps anyone else:

    Code:
    var lobj_SelectBox = document.getElementById("sel_Rate");
    var ls_SelBoxCode = "";
    var i = 0;
    do{
    	lobj_SelectBox.selectedIndex = i;
    	ls_SelBoxCode = (lobj_SelectBox.value).substring(0,5);
    	i++;
    }while (  ( i < lobj_SelectBox.length )  && ( ls_SelBoxCode != ls_Code )  )
    I seems like there should be some way to return the index of a specific value then just set the selectedIndex. If anyone know that syntax, please let me know.

    Thanks!
    -J

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow. That's an odd way to do it. Apparently you aren't aware of the options[] collection.

    Try this.
    Code:
    var lobj_SelectBox = document.getElementById("sel_Rate").options;
    var ls_SelBoxCode = "";
    var i = 0;
    do{
    	ls_SelBoxCode = (lobj_SelectBox[i].value).substring(0,5);
    	i++;
    }while (  ( i < lobj_SelectBox.length )  && ( ls_SelBoxCode != ls_Code )  )
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •