Javascript code working in html but not in JS file.
Posted: Tue Feb 06, 2007 10:48 pm
I have this:
With this html:
How come if I put the code in the header, it works, and if I put it in a seperate JS file I get an error of "Object Expected"?
Code: Select all
function make(){
myPara = document.getElementById("paraID");
form = document.createElement("form");
form.setAttribute("method","post");
form.setAttribute("action","");
form.setAttribute("name","submit_form");
form.setAttribute("id","submit_form");
first_name = document.createElement("input");
first_name.setAttribute("type","text");
first_name.setAttribute("name","first_name");
first_name.setAttribute("value","chris");
form.appendChild(first_name);
myPara.appendChild(form);
} Code: Select all
<body onload="make();"><div id="paraID"></div>
</body>