Results 1 to 8 of 8

Thread: Selected text in a listbox ?

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Selected text in a listbox ?

    Okay this is really confusing me now at this stage.
    I want to put the selected text from a listbox into a textbox.
    I can do everything, except find out what is the selected text.

    Any combination I've tried only seems to pull the first item from the listbox...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    I whipped this up for you


    <html>
    <head>
    <title>Untitled Document</title>

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    function getvalue() {

    document.form1.text1.value = document.form1.list1.value
    }
    // End -->
    </script>

    </head>

    <body>
    <form name="form1">
    <select name="list1" size="1">
    <option value="01">01</option>
    <option value="02">02</option>
    <option value="03">03</option>
    <option value="04">04</option>
    <option value="05">05</option>
    <option value="06">06</option>
    <option value="07">07</option>
    <option value="08">08</option>
    <option value="09">09</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    </select>


    <input name="text1" type="text" size="30" onFocus="getvalue();">

    </FORM>
    </body>
    </html>
    Last edited by davebat; Jun 16th, 2003 at 10:00 AM.

  3. #3
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Code:
    <html>
    <script>
    function test(){
     var s = document.frm.sel;
     var t1 = document.frm.txt;
     var t2 = document.frm.txt2;
    
     t1.value = s.options[s.selectedIndex].text;
     t2.value = s.options[s.selectedIndex].value;
    
    }
    </script>
    <body>
    <form name="frm">
    <table>
     <tr>
       <td>Text=</td>
       <td><input type="text" name="txt"></td> 
     </tr>
     <tr>
       <td>Value=</td>
       <td><input type="text" name="txt2"></td>
     </tr>
     <tr>
       <td><select name="sel">
              <option value=1>one
              <option value=2>two
           </select>
       </td>
       <td><input type="button" onclick="test()" value="selected"></td>
     </tr>
    </table>
    </form>
    </body>
    </html>

  4. #4
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    Dont get cocky Kid

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Originally posted by DeadEyes
    Code:
    <html>
    <script>
    function test(){
     var s = document.frm.sel;
     var t1 = document.frm.txt;
     var t2 = document.frm.txt2;
    
     t1.value = s.options[s.selectedIndex].text;
     t2.value = s.options[s.selectedIndex].value;
    
    }
    </script>
    <body>
    <form name="frm">
    <table>
     <tr>
       <td>Text=</td>
       <td><input type="text" name="txt"></td> 
     </tr>
     <tr>
       <td>Value=</td>
       <td><input type="text" name="txt2"></td>
     </tr>
     <tr>
       <td><select name="sel">
              <option value=1>one
              <option value=2>two
           </select>
       </td>
       <td><input type="button" onclick="test()" value="selected"></td>
     </tr>
    </table>
    </form>
    </body>
    </html>
    How about closing them option tags? Or quite a few other issues.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    no wonder your finally custom if you respond to every single post on this forum

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    So what?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Originally posted by CornedBee
    How about closing them option tags? Or quite a few other issues.
    I normally would, it's one thing XML's got me doing, but it's just a harness.
    I have my editor to load new files like that so I can throw functions together quickly.

Posting Permissions

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



Click Here to Expand Forum to Full Width