javascript - showing the value of textbox under it - Stack Overflow

i want to write the value in textbox under it,how can i do it?thanks in advancei wrote this codes:<h

i want to write the value in textbox under it,how can i do it?thanks in advance

i wrote this codes:

  <html>
   <head>
    <script language="javascript">
        function show (text){
            document.write("text");
        }
    </script>
</head>
<body>
    <input type=textbox name=textbox value="Insert Name"/>
    <input type=button name=button value="OK" onclick=show(textbox.value)/>
 </body>
  </html>

i want to write the value in textbox under it,how can i do it?thanks in advance

i wrote this codes:

  <html>
   <head>
    <script language="javascript">
        function show (text){
            document.write("text");
        }
    </script>
</head>
<body>
    <input type=textbox name=textbox value="Insert Name"/>
    <input type=button name=button value="OK" onclick=show(textbox.value)/>
 </body>
  </html>
Share Improve this question asked Dec 6, 2010 at 16:23 ArashArash 3,07110 gold badges54 silver badges77 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

first of all: document.write replaces document content, use window.alert or such

next, consider enclosing fields in the <form> and then use show(this.form.textbox.value)

thats besides other scripting errors :)

Modify your html like this:

<input type=textbox name=textbox value="Insert Name" id="txt" />
<span id="spn"></span>
<input type=button name=button value="OK" onclick="show();" />

And JavaScript like this:

function show(){   
  document.getElementById('spn').innerHTML = document.getElementById('txt').value;
}

Something like this should work: Working example

<html>
    <head>
        <script language="javascript">
            function show (text){
            document.getElementById("text").innerHTML = text;
            }
        </script>
    </head>
    <body>
        <input type=textbox name=textbox id=textbox value="Insert Name"/>
        <input type=button name=button value="OK" onclick="show(document.getElementById('textbox').value)"/>
        <div id="text"></div>
    </body>
</html>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745267841a4619564.html

相关推荐

  • javascript - showing the value of textbox under it - Stack Overflow

    i want to write the value in textbox under it,how can i do it?thanks in advancei wrote this codes:<h

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信