Results 1 to 2 of 2

Thread: Using Javascript - Display Form Value in the html document

  1. #1
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using Javascript - Display Form Value in the html document

    Hello,

    Kindly refer to attached image.

    When someone selects the option from the drop down menu, The value of the field should be displayed near right side of the drop down.

    Kindly let me know what Javascript code should I use?

    Thanks a million
    Kaushal

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    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 ShowValue(sel,id){
     var obj=document.getElementById(id);
     obj[obj.nodeName.toUpperCase()=='INPUT'?'value':'innerHTML']=sel.value;
    }
    /*]]>*/
    </script></head>
    
    <body>
    <select onchange="ShowValue(this,'txt');" >
    <option value="" >Select</option>
    <option value="value 1" >Option 1</option>
    <option value="value 2" >Option 2</option>
    </select> <span id="txt" ></span>
    <br />
    <select onchange="ShowValue(this,'txt2');" >
    <option value="" >Select</option>
    <option value="value 1" >Option 1</option>
    <option value="value 2" >Option 2</option>
    </select> <input id="txt2" />
    </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/

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
  •