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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing Text Value with a Select list.

    My final desire for what I am trying to do here is concatonate the item to the end of the value of the text input, but I simplified it since nothing was changing in the text field when changing the value of the select. It still has the same problem. The following is the code that I am using:

    Code:
    <select name='itemList" onchange="this.form.lootlist.value=this.options[this.selectedIndex].value">
    <option value="">No Item</option>
    $itemlist
    </select>
    $itemlist is a php variable containing all the options as they are generated from a database. Each is in the form of "<option value='#'># name</option>"

    The current results are that nothing happens. Another problem is that the first two options don't appear... Is there a limit of 130 items in a Select form??

  • #2
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok I fixed that problem but now i have a new one... I got the javascript to work by fixing the quotes then I added back the stuff I removed, to simplify it and figure out what was wrong... and once again it isn't working.

    Code:
    <select name="itemList" onchange="
    if (this.form.lootlist.value != "") {
      this.form.lootlist.value = this.form.lootlist.value + "-"
    }
    this.form.lootlist.value =this.options[this.selectedIndex].value">
    How can I get this to work??
    Last edited by Acaykath; 03-18-2005 at 11:33 PM.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function addvalue(){
    if(document.getElementById('lootlist').value != "")
    document.getElementById('lootlist').value=document.getElementById('itemList').value;
    }
    </script>
    </head>
    
    <body>
    <select id="itemList" name="itemList" onchange="addvalue()">
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    <input type="text" id="lootlist" name="lootlist">
    </body>
    </html>
    adapt it to fit your needs

  • #4
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately, I am not allowed to edit the template that contains the head, so I must have a script intermixed with the code. A script that will add values to a text field seperated by a "-" based on selections fron the list.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <select id="itemList" name="itemList" onchange="if(document.getElementById('lootlist').value != ''){document.getElementById('lootlist').value=document.getElementById('itemList').value + '-';}">
    <option value="1">1</option>
    <option value="2">2</option>
    </select>
    <input type="text" id="lootlist" name="lootlist">
    will that work for you? and your original way might work if you change the double quotes in between the double quotes of the onchange to single quotes
    Code:
    <select name="itemList" onchange="if (lootlist.value != '') {
      lootlist.value = lootlist.value + '-'
    }
    lootlist.value =this.options[this.selectedIndex].value"><option value="1">1</option>
    <option value="2">2</option>
    </select>
    <input type="text" id="lootlist" name="lootlist">
    Last edited by _Aerospace_Eng_; 03-19-2005 at 01:39 AM.

  • #6
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thnx...


  •  

    Posting Permissions

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