View Full Version : onload error
Weirfire
Nov 16th 2004, 6:20 am
When you use the document.<formname>.submit function I get an error that states
document.<formname> is null or not an object
Anyone got any ideas how to get rid of this error? I'm expecting expat to know this 1 :)
expat
Nov 16th 2004, 8:11 am
....Anyone got any ideas how to get rid of this error? I'm expecting expat to know this 1 :)
well we aim to please.....
if it's regarding the bit of script I think you reffer to....
onload <formname> object MUST exist the object is the actual form name used!
.. echo"onLoad='document.SecureForm.submit();'";
(watch the quotes and semikolons)
...echo "<form target=\"_self\" action=\"https://www.paypal.com/cgi-bin/webscr\ (https://www.paypal.com/cgi-bin/webscr)" name=\"SecureForm\" method=\"post\">";
M
Weirfire
Nov 16th 2004, 11:28 am
I have the form inside an IF clause which I think why it's causing the error because when it isn't being called it doesnt exist.
hmmm.. I'll have to to think through the pseudocode :confused:
expat
Nov 16th 2004, 2:13 pm
I have the form inside an IF clause which I think why it's causing the error because when it isn't being called it doesnt exist.
hmmm.. I'll have to to think through the pseudocode :confused:
just generate and else that runs the form to a standard out
eg
if gatway pp
form with pp details
else
form to print or so (action print.php)
end
phrozen_ra
Jan 18th 2005, 1:31 am
use this:
instead
document.<formname>
use
document.getElementById('<formname>')
J.D.
Jan 18th 2005, 5:54 am
use this:
instead
document.<formname>
use
document.getElementById('<formname>')
Using getElementById with form name will only work in IE. If you want this to work in all browsers use form ID. If you want to use form name, you should use getElementsByName (this method returns a node list):
document.getElementById("formid");
document.getElementsByName("formname").item(0);
J.D.
phrozen_ra
Jan 18th 2005, 6:23 am
Using getElementById with form name will only work in IE.
J.D.
False, also works in Fireforx, Netscape, Opera...
show me one browser used by more than 5% of the total users over the internet, which does not work well with getElementById
J.D.
Jan 18th 2005, 6:27 am
False, also works in Fireforx, Netscape, Opera...
show me one browser used by more than 5% of the total users over the internet, which does not work well with getElementByIdNo it doesn't. Try this in IE and FF:
<html>
<head>
<script type="text/javascript">
function myonclick(input)
{
alert(document.getElementById("formid").nodeName);
alert(document.getElementById("formname").nodeName);
alert(document.getElementsByName("formname").item(0).nodeName);
}
</script>
</head>
<body>
<form id="formid" name="formname" action="formid.html">
<input type="button" onclick="myonclick(this)" value="Click!">
</form>
</body>
</html>
ID and name are not interchangeable. There may be only one element with a given ID and there may be more than one with a given name.
J.D.
phrozen_ra
Jan 18th 2005, 7:58 am
it won't logicaly work.... and the bug is here:
alert(document.getElementById("formname").nodeName);
you don't have an id="formname" there.... why do you try to use it?
it works only in IE, because IE is tought that way.... but logicaly you are calling a unknown element by an unexistent ID...
It is somehow my bad cause I forgot to mention that <formname> must be be passed to id also...
There may be only one element with a given ID and there may be more than one with a given name.
and what's bad in having distinct IDs?
phrozen_ra
Jan 18th 2005, 7:59 am
furthermore if you would use CSS... you'd notice that distinct IDs help a lot ;)
J.D.
Jan 18th 2005, 8:18 am
it won't logicaly work.... and the bug is here:
alert(document.getElementById("formname").nodeName);
you don't have an id="formname" there.... why do you try to use it?
it works only in IE, because IE is tought that way.... but logicaly you are calling a unknown element by an unexistent ID...
It is somehow my bad cause I forgot to mention that <formname> must be be passed to id also...
and what's bad in having distinct IDs?Man, it's like you are reading between the lines. The rule is simple - use getElementById only with IDs and use getElementsByName with names, whatever they are. That's it. You quoted in your initial example getElementById used with the form name, which was incorrect. Even if your ID and name are the same, you should've used ID to avoid ambiguity.
J.D.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.