PDA

View Full Version : Simple javascript form submit problem


jkgraham
08-19-2002, 05:20 PM
Hello,

I'm getting the following error when I click on the 'hi' link in the code below.

Object doesn't support this property or method.

This is a very simple javascript and I don't know why it's giving this error. Any help would be greatly appreciated. I get the error in IE v6.0.2600. I plan to do form validation in the doOp function but striped it all out for simplicity.

Thanks,
-Jon

<html>
<head>
<title>Untitled</title>
</head>

<script>
<!--
function doOp() {
var myform = document.blah;
myform.submit();
}
// -->
</script>

<body>
<form name=blah action=testing.php method=post>
<br>
<a href="#" onclick="doOp();">hi</a>
<br>
this is a test
<input type=submit name=submit value=go123 >
</form>

</body>
</html>

Jon Hanlon
08-19-2002, 07:26 PM
[Another "Oldie but Goodie"...]


<input type=submit name=submit value=go123 >


Here you have a submit element (a button), and you name it 'submit'.


myform.submit();


You now have a reference to a form object, and you wish to invoke the 'submit()' method of the form object. But hang on a minute... Sure, the form has a thing called 'submit', but it's a button! You can't execute a button!

Change it to be:


<input type='submit' name='btnSubmit' value='go123'>


Moral: When naming things, stay away from anything that smells like a keyword. Like 'submit' or 'reset' or 'close' or 'open' or 'write' or 'final' or 'continue' or 'new' or 'return'... etc.