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 5 of 5
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    93
    Thanks
    4
    Thanked 0 Times in 0 Posts

    copy a part of a dropdown box selection to a textbox

    Hi,

    I have a form script with a dropdown box listing a lot of albums in this format:
    "The Band - Name of the album"

    there is another feild the users have to fill, it's a textbox where you have to write the band name. This is just making things harder for my members since the band name is already written in the album name, but filling the textbox is required for the process.

    what i would like to do is the following:

    When a user either click the submit button, or automaticaly when the dropdown box value is changed:
    Automaticaly copy ONLY the text BEFORE the " - " from the dropdown to the textbox


    Example:
    If user select entry "abcdefg - hijklmnopqrstuvwxyz" from the dropdown, then:
    Write "abcdefg" in the textbox



    THANKS A LOOOT!

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by anarchoi View Post
    Example:
    If user select entry "abcdefg - hijklmnopqrstuvwxyz" from the dropdown, then:
    Write "abcdefg" in the textbox
    Try this (totally untested). Note that it acts on the option text, not value.
    Code:
     <select onchange='this.form.textField.value=this.options[this.selectedIndex].text.replace(/^([^\-]+)\s*.+$/,"$1")'>
    Where textField is the name of the receiving text field in the same form.

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    93
    Thanks
    4
    Thanked 0 Times in 0 Posts
    AWESOME!!!

    thanks a LOT!!!

    working perfectly

  • #4
    New Coder
    Join Date
    May 2007
    Posts
    93
    Thanks
    4
    Thanked 0 Times in 0 Posts
    this seems to only affect elements in the same form than the dropdown

    is it possible to make it work with a textbox in a different <form>

  • #5
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by anarchoi View Post
    this seems to only affect elements in the same form than the dropdown

    is it possible to make it work with a textbox in a different <form>
    Just change
    Code:
    this.form.textField.value
    to
    Code:
    document.forms.formName.textField.value


  •  

    Posting Permissions

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