[Javascript] IE onclick problem
tedd
tedd at sperling.com
Fri Apr 18 17:36:18 CDT 2008
At 11:57 AM -0700 4/18/08, Howard Jess wrote:
>tedd wrote:
>> At 8:40 AM -0700 4/17/08, Howard Jess wrote:
>>> And finally, it's *far* better to leave this attribute out of
>>> markup altogether, and do everything in javascript:
>>>
>>> <form id="someform"> .... </form>
>>>
>>> <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
>>
>> Please note that while not entering the data required in each text box
>> will generate an alert, it will not stop the submit.
>>
>> I provided a demo here:
>>
> > http://webbytedd.com/ccc/test-onsubmit/index.php
>
>The onsubmit property is a function reference, as I suggested:
>
> form.onsubmit = checkMyForm;
>
>Your example, which doesn't work, says:
>
>window.onload=function() {
> var form=document.getElementById('a');
> if (form) {
> form.onsubmit = checkForm(form);
> }
>}
>
>The line you specify invokes the checkForm function, rather than
>referring to it, and sets the onsubmit property to false; notice
>that you get the alert prompt on first display of the page, *before*
>you hit submit.
>
>Try:
> window.onload = function() {
> var form = document.getElementById('a');
> form.onsubmit = function() {return checkForm(form)};
> }
>
>or if you don't like that, try:
> window.onload = function() {
> var form = document.getElementById('a');
> function submitter() {
> return checkForm(form);
> }
> form.onsubmit = submitter;
> }
>
Okay, I understand both of those.
Those are more in keeping with the original post question, which
discussed the difference between "return checkForm(this)" and
"checkForm(this)" -- the later not working.
Thanks,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
More information about the Javascript
mailing list