最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论