Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting a <select> field automatically to a value

    Hi,

    im desperately trying to set a <select> field to a specific value.

    Im loading all contents (<option>) of the select-field from a db.
    Im loading another value from database as well.

    With having the <select> field filled with the values from the first db-query -> e.g. Berlin,Munisch,London,Paris
    and the result of the second db-query being London, i now want to set the select field to the third <option> which already is Londondon in the list.

    I tried serveral ways with javascript via selected, selectedIndex and options[x] - but cant really figure out a way to solve this.

    Thanks a lot for any help or tips on this problem !

    tdmf

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, you could do <option value="blah" selected>(handled by server-side) ..
    for JS to set the selected you could do it two ways..
    Code:
    object.options[2].selected = true;
    object.selectedIndex = 3;
    if that didn't help.. post some code.


  •  

    Posting Permissions

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