Arash
Arash

Reputation: 3051

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>

Upvotes: 1

Views: 5561

Answers (3)

subhaze
subhaze

Reputation: 8855

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>

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382656

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;
}

Upvotes: 2

Free Consulting
Free Consulting

Reputation: 4402

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 :)

Upvotes: 2

Related Questions