473,651 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with form.elements.l enght

Hi,

I've written some code:
function onSubmit(form){
for (var i = 0; i < form.elements.l enght; i++){
if (form.elements[i].disabled == 1)
form.elements[i].disabled = 0;
}
}

....

<form action="step3.j sp" method="get" name="myForm"
onsubmit="onSub mit(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.l enght'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 7302
VK

Pudlik, Szymon wrote:
Hi,

I've written some code:
function onSubmit(form){
for (var i = 0; i < form.elements.l enght; i++){
if (form.elements[i].disabled == 1)
form.elements[i].disabled = 0;
}
}

...

<form action="step3.j sp" method="get" name="myForm"
onsubmit="onSub mit(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.l enght'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.l enght'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*****@CUTTHI Sdesy.de>
Hi,

I've written some code:
function onSubmit(form){
for (var i = 0; i < form.elements.l enght; i++){
if (form.elements[i].disabled == 1)
form.elements[i].disabled = 0;
}
}

...

<form action="step3.j sp" method="get" name="myForm"
onsubmit="onSub mit(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.l enght'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*****@CUTTHI Sdesy.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.l enght; i++){
if (form.elements[i].disabled == 1)
form.elements[i].disabled = 0;
}
}

...

<form action="step3.j sp" method="get" name="myForm"
onsubmit="onSub mit(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.l enght'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*****@agrico reunited.com>
comp.lang.javas cript 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

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

Similar topics

3
5756
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> <option>Frog</option> etc etc and is in an include file... where the word i.e. worm sources the image ..images/worm.gif - simple so far...
2
3463
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 "undefined". So I tried : document.forms.mySelect.lenght = undefined
22
3316
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: <form name="myform"> <input name="myinput" /> </form> 1. var input = document.forms.myform.myinput;//from nn3+ 2. var input = document.forms.myinput;//from nn3+
0
5504
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) modification. Don't blame me, I know using search/replace works most of the times. At first, I used CREATE TYPE syntax to map Oracle nvarchar2 to PostgreSQL varchar type (see code #1). The code seems to be the equivalent of:
0
857
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
3396
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
2556
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 use to run a UM program, I kept on getting error messages. I have used someone else's implementation and it runs fine. I have compared my code with other's and I still can't figure it out what's wrong with mine. So please help me out, after 3...
13
2644
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 longer works. (I think it is considering the embed tag as an element in my form and I think that's causing the problem.) I think adding and specifying to only look at a div tag within the form would solve the problem but I'm not sure. Can someone...
0
8352
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.