www.webdeveloper.com
Results 1 to 3 of 3

Thread: InnerHTML output into a input text box?

  1. #1
    Join Date
    Sep 2009
    Posts
    159

    InnerHTML output into a input text box?

    hello. This might be a silly question, but I'm having no clue why it wouldn't work out. I'm simply trying to have a string, "job done", into a input text box.

    Here's the code I'm working on.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <head>
    	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    	<title>text output testing</title>
    	<script language="javascript" type="text/javascript">
    		function print()
    		{
    			document.getElementById('output').innerHTML="job done"
    		}
    	</script>
    </head>
    
    <html>
    <body>
    <input type="text" id="output"><input type="button" onclick="print();" value="Go">
    </body>
    </html>
    I thought this should work like a breeze, but it makes my bang my head on the wall. Any suggestion will be appreciated.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    print is a javascript reserved word. It is a method of the window Global Object, window.print(). Change the name of your function: Print() or printIt() or whichever

    On the other hand, the non empty tags (such as INPUT) have no innerHTML, they might have the value attribute

    And, the last but the least, there is a mismatch between your Doctype (HTML transitional) and the notation of some of your tags < ... />, which is an XHTML notation, not an HTML one. And you miss your opener tag <html>. And language is deprecated,
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function printIt(){
    document.getElementById('output').value="job done"
    }
    </script>
    </head>
    <body>
    <form action="">
    <input type="text" id="output"><input type="button" onclick="printIt();" value="Go">
    </form>
    </body>
    </html>
    You see how many errors were?
    Last edited by Kor; 12-13-2009 at 11:32 AM.

  3. #3
    Join Date
    Sep 2009
    Posts
    159
    Thx for your detailed answer. Worked like a charm.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles