Thursday, July 24, 2008

JavaScript == operator

Keep in mind that 0 == "" returns true in JavaScript. For a more detailed explanation (and a lover's lament) see Chipmunkan's blog post.

Tuesday, July 8, 2008

Dynamically altering a form's onsubmit event handler

Suppose you have a form and you wish to alter the form's onsubmit event handler on-the-fly...

For example, your form might consists of two radio buttons and a submit button. Depending on which radio button has been selected prior to the user's submitting the form, you want the onsubmit event handler to change.

This works in Firefox, but not IE:
form.setAttribute("onSubmit", "alert('hi'); return false;");

This works in both:
frm.onsubmit=test;
function test() {
alert('hi');
return false;
}