Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have following HTML page that uses XHTML 1.0 that used to grab a value from an HTML form and display it using a JavaScript function. The JS function and the full source code is at the below.

XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title><!-- Insert your title here --></title>
    <script type="text/javascript">
        
        function testVariable(){
            
            var strText = document.getElementById("textone");
            document.write(strText);
                    
        }
        
        
    </script>
</head>

<body>

<form action="" method="get" >
    
    <input type="text" id="textone" name="textone"></input>
    <input type="button" value="Submit" onclick="testVariable();false"></input>
      
</form> 
</body>
</html>


But my output is like at the below.

-----Output--------

[object HTMLInputElement]

-------------------

I can't figure out what I ahve done wrong. So could someone help me to solve this matter?

Thanks & regards,
Chiranthaka.
Posted

You were printing the control object, should be its value instead:
document.write(strText.value);
 
Share this answer
 
v2
Demo[^]
try with
JavaScript
document.write(strText.value);
 
Share this answer
 
Comments
Chiranthaka Sampath 15-Jul-14 2:48am    
Ok its working fine. Now I want to display it just below the form. How am I suppossed to do that?
DamithSL 15-Jul-14 2:52am    
Chiranthaka Sampath 15-Jul-14 3:15am    
Ok all my problems were cleared by you. Thanks for the help.

Thanks,
Chiranthaka
confusedtushar 1-Mar-18 4:59am    
@damithSL i need to display whole form on same page.
can u help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900