Shairdil
Shairdil

Reputation: 1

How to display manually entered string values in text boxes using JavaScript & HTML on the same webpage?

I am trying to write the following source code for displaying the manually entered(From Keyboard) text in text boxes using the submit button: HTML + JavaScript Source:

<html>
<head>
    <title>Insert Values</title>
</head>
<body>
    <form id="form1">
        Title: <input type="text" id="title1" size="25"><br /><br />
        Description: <input type="text" id="desc1" size="55"><br /><br />
        <input type="button" value="Submit" onclick="doit();">
    </form>
    <script type="text/javascript">
       function doit(){
            var title = document.getElementById("title1").value;
            var desc = document.getElementById("desc1").value;
            document.write("<h3>Title : </h3>" + title + <br />);
            document.write("<h3>Description : </h3>" + desc);
            }
    </script>            
</body>

When I use the debugger to trace errors, it gives the message "unfound syntax error" using the browser's debugger. When the webpage is loaded in the browser, it displays the text boxes & the submit button, though after entering text & clicking on the submit button, nothing happens!

Upvotes: 0

Views: 3211

Answers (4)

     function doit(){
     var myValue=document.getElementById('myTextBox').value;

     if(myValue==0){
     alert('Pleae Enter Real Value');
     }

     var myTitle=document.getElementById('title');
     myTitle.innerHTML=myValue;
}
<h1 id="title">Title</h1>
<input type="text" id="myTextBox">
<input type="submit" value="Click me!!" onClick="doit()">

Upvotes: 0

billy
billy

Reputation: 56

also close your html tag

   </html>

Upvotes: 1

Vlad DX
Vlad DX

Reputation: 4730

You just forgot to wrap <br /> by quotes in 15th line:

document.write("<h3>Title : </h3>" + title + "<br />");

Upvotes: 1

hungndv
hungndv

Reputation: 2141

Here you are:

   function doit() {
       var title = document.getElementById("title1").value;
       var desc = document.getElementById("desc1").value;
       document.write("<h3>Title : </h3>" + title + "< br / >"); // HERE
       document.write("<h3>Description : </h3>" + desc);
   }

Hope this help.

Upvotes: 2

Related Questions