"Pudlik, Szymon" <sp*****@CUTTHISdesy.de> wrote in message
news:dc***********@claire.desy.de...
Hi,
I've written some code:
function onSubmit(form){
for (var i = 0; i < form.elements.lenght; i++){
if (form.elements[i].disabled == 1)
form.elements[i].disabled = 0;
}
}
...
<form action="step3.jsp" method="get" name="myForm"
onsubmit="onSubmit(this)">
...
</form>
I want to turn on all of <select> elements on my form by set their
field 'disabled' to false. Loop doesn't work. I've tried to get
form.elements.lenght's value by putting it to alert box. IE (NS also)
said "undefined". Where is the problem?
length, not lenght.
Also, the disabled property contains a boolean, not an number. Although
type conversion will probably make the code work, it's best to stick to
the type the property expects. As well, it appears you are testing to
see whether every element is disabled, and if it is, you are enabling
it. If all you want is to disable <select> elements, you should be
testing for them before disabling every element on the page:
function onSubmit(f) {
f = f.elements;
for (var i = 0; i < f.length; ++i) {
if (f[i].type.indexOf('select') > -1 &&
!f[i].disabled) {
// if the element type is select-one
// or select-multiple, and it's not currently
// disabled, disable it
f[i].disabled = true;
}
}
}
Be aware, if something goes wrong during the form submission, you have
now left the user with a useless form because all the <select> elements
are disabled.
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq