SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question select box name to Text box ?

    hi all

    I have two elements in a page.

    one select box and a Text box.Select box contains name.when i choose a name
    that name should be displayed into the text box.

    please help me.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Untitled Document</title>
            <link rel="stylesheet" type="text/css" media="screen" />
            <style type="text/css"></style>
            <script type="text/javascript">
                function transfer(from, to) {
                    if(typeof(to) == 'string')
                        to = document.getElementById(to);
                    to.value = from.options[from.selectedIndex].value;
                }
            </script>
        </head>
        <body>
            
            <select onchange="transfer(this, 'to');">
                <option>Select a Name</option>
                <option value="Gavin">Gavin</option>
                <option value="Bob">Bob</option>
                <option value="Jane">Jane</option>
                <option value="John">John</option>
            </select>
    
            <input type="text" id="to" />
    
        </body>
    </html>


  3. #3
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to write a handler for a change event.
    something like:

    Code:
    <input type="text" name="myText" id="myText" />
    <select name="mySelect" id="mySelect" onchange="setText(this.options[selectedIndex].value, 'myText');">
      <option value="one">1</option>
     <option value="two">2</option>
    </select>
    The the javascript to make it work

    Code:
    function updateField(fieldName, id) {
    	document.getElementById(id).value = fieldName;
    }
    Hope this helps.
    Rich
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site

  4. #4
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks richtestani and gRoberts.Thanks for your valuable time and codes.


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
  •