Results 1 to 7 of 7

Thread: Listbox and textbox help

  1. #1
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default Listbox and textbox help

    instead of "place1,place2, and place3 the showing up in the text box. I actually want a small description to go in the textbox instead of what is in the listbox.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <SCRIPT>  
    <!--  
      
    function combotext_onkeydown(e,oText,oSelect){  
      
      keyCode = e.keyCode;  
      
      if (keyCode == 40 || keyCode == 38) {  
        oSelect.style.display = 'block';  
        oSelect.focus();  
        comboselect_onchange(oSelect, oText);  
      }  
      else if (keyCode == 13) {  
        e.cancelBubble = true;  
        if (e.returnValue) e.returnValue = false;  
        if (e.stopPropagation) e.stopPropagation();  
        comboselect_onchange(oSelect, oText);  
        oSelect.style.display='none';  
        oText.focus();  
        return false;  
      }  
      else if(keyCode == 9) return true;  
      else { //alert(keyCode);  
      
        oSelect.style.display = 'block';  
      
        var c = String.fromCharCode(keyCode);  
        c = c.toUpperCase();   
        toFind = oText.value.toUpperCase() + c;  
      
        for (i=0; i < oSelect.options.length; i++){  
           nextOptionText = oSelect.options.text.toUpperCase();  
      
            if(toFind == nextOptionText){  
                oSelect.selectedIndex = i;  
                break;  
            }  
      
            if(i < oSelect.options.length-1){  
               lookAheadOptionText = oSelect.options[i+1].text.toUpperCase() ;  
               if( (toFind > nextOptionText) &&   
                  (toFind < lookAheadOptionText) ){  
                  oSelect.selectedIndex = i+1;  
                  break;  
               }  
             }  
             else {  
               if(toFind > nextOptionText){  
                   oSelect.selectedIndex = oSelect.options.length-1; // stick it at the end  
                   break;  
               }  
           }  
        }  
      }  
    }  
      
      
    function comboselect_onchange(oSelect,oText) {  
      if(oSelect.selectedIndex != -1)  
        oText.value = oSelect.options[oSelect.selectedIndex].text;  
    }  
      
    function comboselect_onkeyup(keyCode,oSelect,oText){  
      if (keyCode == 13) {  
        comboselect_onchange(oSelect, oText);  
        oSelect.style.display='none';  
        oText.focus();  
      }  
    }  
      
    // -->  
    </SCRIPT>
    <body>
    <FORM name="form1">
      <table width="617" border="1" align="center" bordercolor="#990000">
        <tr>
          <th scope="col">Places</th>
          <th scope="col">Description</th>
        </tr>
        <tr>
          <th width="219" scope="row"> <SELECT NAME="selectInput1" SIZE="8" ONCHANGE="comboselect_onchange(this, this.form.textInput)" >
            <option>place1</option>
            <option>place2</option>
            <option>place3</option>
    		
            </SELECT>		</th>
          <th width="382" scope="row"> 
              <textarea name="textInput" cols="20" rows="10" id="textInput"></textarea>        </th>
        </tr>
      </table>
    </FORM>
    </BODY>
    </html>
    Any Help?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You could give each option a value attribute and pull options.value instead of options.text.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    You could give each option a value attribute and pull options.value instead of options.text.

    I changed that in the script tags but that didnt do any good. It still does the same thing.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I don't think you understood me. This demo shows that the value may be retrieved instead of the text and that the value may be completely different than the text:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Select Options Value - Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function demo(el){
    alert(el.options[el.selectedIndex].value)
    }
    </script>
    </head>
    <body>
    <select name="selectInput1" onchange="demo(this)" >
            <option value="A longer description of Place 1">place1</option>
            <option value="The movie version of a longer description of Place 2">place2</option>
            <option value="Bob's your Uncle's longer description of Place 3">place3</option>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    sorry but I dont understand how to make the description show up in a textbox and not an alert box.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Select Options Value to Textarea - Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function demo(el){
    el.form.textInput.value=el.options[el.selectedIndex].value;
    }
    </script>
    </head>
    <body>
    <form action="">
    <table>
    <tr>
    <td><select name="selectInput1" onchange="demo(this)">
            <option value="A longer description of Place 1">place1</option>
            <option value="The movie version of a longer description of Place 2">place2</option>
            <option value="Bob's your Uncle's longer description of Place 3">place3</option>
    </select></td>
    <td><textarea name="textInput" cols="30" rows="5">A longer description of Place 1</textarea> </td>
             </tr>
             </table>
             
    
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    Gracious, Senor!!!

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
  •