简体   繁体   中英

showing the value of textbox under it

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM