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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to put select value on input box

    I am trying but I can't figure it out, let say you select something on your select values, after selecting that value, how can you dynamically put that value on an input box?

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function TextBox(sel,nme){
     sel.form[nme].value=sel.value;
    }
    /*]]>*/
    </script></head>
    
    <body>
    <form>
    <select name="select" size="1" onchange="TextBox(this,'textbox');">
    <option value="1" >Choice 1</option>
    <option value="2" >Choice 2</option>
    <option value="3" >Choice 3</option>
    <option value="4" >Choice 4</option>
    </select>
    
    <input name="textbox" />
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Within the scope of a form, elements can be addressed directly by name. So that example could use:

    Code:
    function TextBox( sel, nme ){
     nme.value = sel.value;
    }
    
    ...........
    
    <select name="select" size="1" onchange="TextBox( this, textbox );">


  •  

    Posting Permissions

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