Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Form field arrays in IE 5+
- From: christ at saeweb.com (Chris Tifer)
- Subject: [Javascript] Form field arrays in IE 5+
- Date: Thu Apr 24 12:35:27 2003
Peter, so what exactly is it you're trying to do? Is this part of a function that's called when someone tries to submit a form? When the element loses focus? Through an onChange event? The reason I ask is because I'll give you some code that'll work, but the basic problem you're having is that you're grabbing one element at a time. Now when you check the length of that, naturally, it's only one element. Now if you were to do something like this once you came across a radio collection (or checkbox): var objArrEl = document.mainForm.elements[currentField.name] THEN you'd have an array of elements since your code was initially wanting to only look at one particular element and this is saying "Let's look at all the elements with this name".. Get my drift? Chris Tifer http://emailajoke.com ----- Original Message ----- From: "Peter Brunone" <peter@xxxxxxxxxxx> To: <javascript@xxxxxxxxxx> Sent: Thursday, April 24, 2003 1:00 PM Subject: [Javascript] Form field arrays in IE 5+ > I could've sworn I've done this before. > > I'm looping through a form's elements, and when I get to a radio button or checkbox, I want to determine whether any options are checked. Now, as far as I can remember, if you have a radio/checkbox collection with all elements named the same, then you can treat it as an array... BUT, for some reason, IE is still acting as if each of them is a separate entity, which really gives me no way to tie them together. Below is a sample piece of script I'm using to get the pieces, but the browser refuses to believe that four <input type="radio"> with the same name are really pieces of one collection. > > for(var i=0;i<document.mainForm.elements.length;i++) { > if(currentField.type == "text") { > if(currentField.value == "") { isValid = 0 } > } > else if(currentField.type == "radio") { > isChecked = 0; > j = 0; > for(var j=0;j<currentField.length;j++) { > if(currentField[j].checked == true) {isChecked = 1} > alert(currentField.value + " " + currentField.checked); // Debugging > } > if(isChecked == 0) { isValid = 0 } > } > } > > What am I missing? > > Cheers, > > Peter > _______________________________________________ > Javascript mailing list > Javascript@xxxxxxxxxx > https://lists.LaTech.edu/mailman/listinfo/javascript
- References:
- [Javascript] Form field arrays in IE 5+
- From: Peter Brunone
- [Javascript] Form field arrays in IE 5+
- Prev by Date: [Javascript] Form field arrays in IE 5+
- Next by Date: [Javascript] overflow: auto
- Previous by thread: [Javascript] Form field arrays in IE 5+
- Next by thread: [Javascript] Form field arrays in IE 5+
- Index(es):