[Javascript] IE onclick problem

David Dorward david at dorward.me.uk
Fri Apr 18 13:50:26 CDT 2008


On 18 Apr 2008, at 18:48, tedd wrote:
>>   <script type="text/javascript">
>>   window.onload=function() {
>>     var form=document.getElementById('someform');
>>     if (form) form.onsubmit = checkMyForm;
>>   }
>>   </script>
>
> Howard:
>
> I spoke too soon -- take a look at this:
>
> http://webbytedd.com/ccc/test-onsubmit1/index.php


You have:
		form.onsubmit = checkForm(form);

So you are calling checkForm, with the the form as an argument, and  
assigning the return value to onsubmit.

The return value is going to be false (since the form isn't filled in  
at load time), but it needs to be a function.

		form.onsubmit = function (f) {
				return function () {
					checkForm(f)
				};
			}(form);

Here I generate an anonymous function with one argument, and call it  
with the form as the argument immediately. The return value (another  
anonymous function, which calls checkForm when it is run) is assigned  
to onsubmit.

-- 
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/





More information about the Javascript mailing list