'Lost' function return value: what am I doing wrong?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

'Lost' function return value: what am I doing wrong?

From: <bdobby@fish.co.uk>
Date: Mon Jan 09 2006 - 09:12:28 CET

Hi.
  I am relatively new to js, but I did think I was starting to get the
hang of it. Then this happened...

I have a form with an onsubmit event handler:
          <form id="uploadForm" method="post" action="..."
onSubmit="checkDates()">

The event handler does some minor validation, then returns true or
false:
        function checkDates(y, m, d) {
>>snip<<
                if (endDate.getTime() >= startDate.getTime())
                        return true;

                alert("Start date must precede end date");
                return false;
        }

(The arguments to the function are used when it is called elsewhere,
not as onsubmit.)

I also have a library class which needs to process the form submit, so
it hooks onsubmit like this:
MyClass.setOnSubmit = function(listId) {
        var list = document.getElementById(listId);
        var form = list.form;

        var f = form.onsubmit;
        if (typeof f == "function") {
                form.oldOnSubmit = f;
                form.onsubmit = function(){
                 var ok = this.oldOnSubmit();
                if (ok)
                    return MyClass.onsubmit(listId);
                else
                   return false;
                                                };
        }
        else
                form.onsubmit = function(){MyClass.onsubmit(listId);};
}

My problem is that the value returned from oldOnSubmit and stored in ok
appears as 'void'. This happens in IE 6 and in FireFox 1.07. Can anyone
explain what's happening?

TIA
Brian
Received on Tue Jan 17 17:05:29 2006