[Javascript] disabling form on submit

Hakan Magnusson hakan at backbase.com
Tue May 25 05:50:36 CDT 2004


Hugo Ahlenius wrote:
> But the discussion gave me an idea: one could, on the submit event a)
> create a bunch of hidden form elements duplicating the existing ones,
> and b) then disable the non-hidden form elements.

What kind of form elements are you using on the page? The attribute 
"readonly" will not affect the results of your post, so if you can set 
all elements to readonly you'll have a usable solution. When it comes to 
the "disabled" look, that's quite easily simulated through CSS.


form.isEnabled input {   /* Normal look */
	border: 1px solid #000000;
	background: #ffffff;
	color: #000000;
}

form.isDisabled input {  /* Low contrast, "disabled" look */
	border: 1px solid #808080;
	background: #b0b0b0;
	color: #606060;
}

With some more work you'll be able to change the appearance of all form 
elements by just changing the class of your parent form. On submit, 
simply set all form elements to 'readonly' and change the class of the 
form, voila!

Those form elements that do not support 'readonly' (you'll have to check 
it up yourself) could be disabled by simply setting the onfocus handler 
to blur itself again.

Regards,
H



More information about the Javascript mailing list