I have this .js file called by my page. The function I'm caling with my onclick is working before the button is clicked.

window.onload = function() 
    document.getElementById('clickMe').onclick = testOne();

function testOne()
    var para = document.getElementsByTagName('p');
    var length = para.length;

    for(i=0; i<length; i++)
        //document.getElementById(para[i]).style.font = "Arial";

And, my HTML:

            <script type="text/javascript" src="test.js"></script> 
            <div id="main"> 
                <h1 id="title">Test.JS</h1> 
                <p id="first">Hello,</p> 
                <p id="second">Again.</p> 
                <p id="third">Hello.</p> 
            <div id="form"> 
                <input type="text" id="txtInput" /> 
                <input type="submit" value="Click Me" id="clickMe" /> 

Thank you,


Not sure if this is right but try emoving brackets:

document.getElementById('clickMe').onclick = testOne;

DaveAmour, thank you. Couldn't see the tree for the forest.

Now... On to my next mistake.

I think what is happening here is that javascript is seeing the document.getElementById('clickMe').onclick = testOne(); and is assigning the document.getElementById('clickMe').onclick value to whatever testOne(); returns. so just try doing this:

<input type="submit" value="Click Me" id="clickMe" onclick="testOne()"/>