473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Problem with form.elements.lenght

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?

Greetings, Szymon Pudlik.
Aug 3 '05 #1
12 7266
VK

Pudlik, Szymon wrote:
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?

Greetings, Szymon Pudlik.

document.forms[0].elements[i]

Aug 3 '05 #2
On 03/08/2005 17:38, Pudlik, Szymon wrote:

[snip]
if (form.elements[i].disabled == 1)
form.elements[i].disabled = 0;
The disabled property is a boolean, not a number.

[snip]
I want to turn on all of <select> elements on my form by set their
field 'disabled' to false.
Your code would enable all form controls, not just SELECT elements.
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?


You're spelling length incorrectly.

function onSubmit(f) {
var e = f.elements,
i, n;

for(i = 0, n = e.length; i < n; ++i) {
if(/^select/.test(e[i].type)) {e[i].disabled = false;}

/* ...or if('select-one' == e[i].type) {...} */
}
}

Hope that helps,
Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Aug 3 '05 #3
VK wrote:
document.forms[0].elements[i]


Hi,
it is also not working. I've tried this before I've written on this group...

Cheers, Szymon.
Aug 3 '05 #4
alu

"Pudlik, Szymon" <sp*****@CUTTHISdesy.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?

Greetings, Szymon Pudlik

Spelling error. All instances of 'length' are spelled incorrectly.
-alu
Aug 3 '05 #5
"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
Aug 3 '05 #6

Michael Winter wrote:
You're spelling length incorrectly.
You are right. I've done a mistake.
function onSubmit(f) {
var e = f.elements,
i, n;

for(i = 0, n = e.length; i < n; ++i) {
if(/^select/.test(e[i].type)) {e[i].disabled = false;}

/* ...or if('select-one' == e[i].type) {...} */
}
}


I've tried first option:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.lenght; i++){
if(/^select/.test(el[i].type)){
el[i].disabled = false;
}
}
}

and second:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.lenght; i++){
if('select-one' == el[i].type){
el[i].disabled = false;
}
}
}

and both doesn't work. All my select items are still disabled :(
Is it possible that I do not understand what is "/^select/" and
'select-one'.. Would you like to explain me that?

Greetings, Szymon Pudlik.
Aug 3 '05 #7

Michael Winter wrote:
You're spelling length incorrectly.
You are right. I've done a mistake.
function onSubmit(f) {
var e = f.elements,
i, n;

for(i = 0, n = e.length; i < n; ++i) {
if(/^select/.test(e[i].type)) {e[i].disabled = false;}

/* ...or if('select-one' == e[i].type) {...} */
}
}


I've tried first option:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.lenght; i++){
if(/^select/.test(el[i].type)){
el[i].disabled = false;
}
}
}

and second:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.lenght; i++){
if('select-one' == el[i].type){
el[i].disabled = false;
}
}
}

and both doesn't work. All my select items are still disabled :(
Is it possible that I do not understand what is "/^select/" and
'select-one'.. Would you like to explain me that?

Greetings, Szymon Pudlik.

Aug 3 '05 #8

Michael Winter wrote:
You're spelling length incorrectly.
You are right. I've done a mistake.
function onSubmit(f) {
var e = f.elements,
i, n;

for(i = 0, n = e.length; i < n; ++i) {
if(/^select/.test(e[i].type)) {e[i].disabled = false;}

/* ...or if('select-one' == e[i].type) {...} */
}
}


I've tried first option:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.lenght; i++){
if(/^select/.test(el[i].type)){
el[i].disabled = false;
}
}
}

and second:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.lenght; i++){
if('select-one' == el[i].type){
el[i].disabled = false;
}
}
}

and both doesn't work. All my select items are still disabled :(
Is it possible that I do not understand what is "/^select/" and
'select-one'.. Would you like to explain me that?

Greetings, Szymon Pudlik.
Aug 3 '05 #9
On 03/08/2005 18:27, Pudlik, Szymon wrote:
Michael Winter wrote:
You're spelling length incorrectly.
You are right. I've done a mistake.


And you're still doing it. There is no lenght property (anywhere in the
DOM) so el.lenght evaluates to undefined. In relational comparisons such as

i < el.lenght

undefined operands cause the expression to evaluate to false. This means
that your loop is never entered.

Spell length properly as it is in my original code (or just use it
verbatim); it ends 'th', not 'ht'.

[snip]
Is it possible that I do not understand what is "/^select/" and
'select-one'.. Would you like to explain me that?


All form controls have a type property that reflects the type of
control. SELECT elements have two possible values: select-one and
select-multiple. When the boolean attribute, multiple, is added to a
SELECT element, the type property will contain the latter (select-multiple).

I assumed that you're using singular SELECT elements (rendered as a
drop-down, not a list), so I suggested a direct test of 'select-one' as
that should be quicker. But, just in case, the regular expression,

/^select/

could be used to check for either of the two values (it will match any
string that begins [^] with the sequence, select).

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Aug 3 '05 #10

"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?

Greetings, Szymon Pudlik.


just use this instead,

document.getElementById("yourformidhere").getEleme ntsByTagName("*");
Aug 3 '05 #11
Thanks for all answers.

I do this like that:

function onSubmit(form){
var el = form.elements;
for (var i = 0; i < el.length; i++){
if('select-one' == el[i].type){
el[i].disabled = false;
}
}

}

and it works :)

Thanks.
Szymon Pudlik.
Aug 4 '05 #12
"cosmic foo" <so*******@fromnothing.com> wrote in message
news:5w*******************@news20.bellglobal.com.. .

"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?

Greetings, Szymon Pudlik.


just use this instead,

document.getElementById("yourformidhere").getEleme ntsByTagName("*");


Why not use document.forms[...].elements[...] when it is going to work
in more browsers than your example, since it works in any browser that
supports your example, as well as a collection of other browsers.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Aug 5 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lee Mundie | last post by:
Hi there, Simple problem here but can't seem to fix it! Okay, I have a select list from which people choose avatars... the list is option values ie. <option>Worm</option> ...
2
by: Kevin Auch | last post by:
Hi all, I have a problem (a simple but incredible problem !). On a form, I have a Select element which is mulitple. I tried to get the number of options of this Select but it always return...
22
by: Luke | last post by:
Elements with name attribute: form, input, textarea, a, frame, iframe, button, select, map, meta, applet, object, param, img (if you know more reply...) Methods of addresing html elements:...
0
by: Jean-Michel POURE | last post by:
Dear friends, I studying the possibility to port Compiere CRM from Oracle to PostgreSQL. As Compiere evolves nearly everyday in CVS, I would like to run the Oracle code without (too much)...
0
by: Nikolay Petrov | last post by:
I have this probelm In table of my SQL database I have column which should contain text, which contains the ID of the row in Dataset. My table has this columns ID Date Time UniqueID Status
2
by: windsorben | last post by:
How would I pass the student's final score to a hidden form field? <script language="javascript" type="text/javascript"> <!-- var score = 0;
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
13
by: windsorben | last post by:
I have some javascript that checks whether or not an answer is correct. It was working fine when the question was asked with text but now that I'm asking the question with audio, the javascript no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.