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
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\" name=\"SecureForm\" method=\"post\">"; M
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
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
use this: instead document.<formname> Code (markup): use document.getElementById('<formname>') Code (markup):
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); Code (markup): 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
No 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> Code (markup): 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.
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.