JavaScript and client side scripting.
Moderator: General Moderators
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Tue Feb 06, 2007 10:48 pm
I have this:
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);
}
With this html:
Code: Select all
<body onload="make();"><div id="paraID"></div>
</body>
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"?
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Tue Feb 06, 2007 11:02 pm
Sounds like a document error. Try document.form (and maybe change that variable name) and document.first_name.
nickvd
DevNet Resident
Posts: 1027 Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:
Post
by nickvd » Wed Feb 07, 2007 12:17 am
When you put the js into an external file, did you remove the onload="make();" attribute?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Wed Feb 07, 2007 12:33 am
I'm willing to bet it's an inclusion problem. Your script tag MUST have a closing tag (not a single, closed element) and must specify
src="/path/to/your.js"
so make it look like this:
Code: Select all
<script type="text/javascript" src="/path/to/your.js"></script>
The "type" attribute is optional, but I use it anyway.
Make sure the element is empty as well.
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Wed Feb 07, 2007 3:44 pm
My <script></script> is fine, and everything else is fine, but I ran it in Firefox to get the error, and it says make(); is not defined, but its in the external js file. Any ideas why?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Wed Feb 07, 2007 4:17 pm
is your path correct? Recheck your absolute/relative directories and your spelling.
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Wed Feb 07, 2007 4:39 pm
i got it to now just give me myPara has no properties... any ideas? [it was a */ causin the error before]