www.webdeveloper.com
Results 1 to 2 of 2

Thread: Output javascript to html - how do I do it?

  1. #1
    Join Date
    May 2012
    Posts
    1

    Output javascript to html - how do I do it?

    Hi all,

    First post and most definietly wont be the last as Im trying to learn a bit of html with javascript. I have a script which displays the current user accessing the page. What I am trying to do is have a file containing all my js code and then display the necessary's on my html page.

    This is a snippet of my index.html
    Code:
    <body>
    
    <div id="page-container">
    
    <div id="main-nav">
    	<dl class="hidden">
    		<dt id="about"><a href="#">About</a></dt>
    		<dt id="services"><a href="#">Services</a></dt>
    		<dt id="portfolio"><a href="#">Portfolio</a></dt>
    		<dt id="contact"><a href="#">Contact Us</a></dt>
    	</dl>
    </div>
    	
    <div id="header">
    	<h1><img src="images/headers/Logo.gif" width=276" height=182" alt="Test" border="0" /></h1>
    </div>
    	
    	<div id="sidebar-a">
    	
    	</div>
    	
    	<div id="content">
    
    	</div>
    	
    <div id="footer">
    	<div id="altnav">
    		<a href="#">Home</a> - 
    		<a href="#">Home 1</a> - 
    		<a href="#">Home 2</a> - 
    		<a href="#">Contact</a> - 
    	</div>
    </div>
    <span id="username"></span>
    <script type="text/javascript" src="scripts/script.js"></script>
    </body>
    
    </html>
    As I understand it the code at the bottom
    Code:
    <script type="text/javascript" src="scripts/script.js"></script>
    points to my javascript code which is here:
    Code:
    <script type="text/javascript" language="javascript">    
    var objUserInfo = new ActiveXObject("WScript.network");  
    document.getElementById('username').innerHTML = objUserInfo.Username;
    </script>
    And should display the logged in user here:
    Code:
    <span id="username"></span>
    But its currently blank - any ideas please?

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Your index.html page is not well formed: doctype, html, head missing.
    It works for me in IE when I use the following HTML:


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Test page</title>
    </head>
    <body>
    <span id="username"></span>
    <script type="text/javascript" language="javascript">
    var objUserInfo = new ActiveXObject("WScript.network");
    document.getElementById('username').innerHTML = objUserInfo.Username;
    </script>
    </body>
    </html>

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