[thelist] Brain Addled Javascript....
Anthony Baratta
Anthony at Baratta.com
Fri Jun 22 19:10:40 CDT 2001
At 04:36 PM 6/22/2001, you wrote:
>let's break it down piece by piece. you'll kick yourself afterwards, it's
>so simple. *grin*
You're right. I'd kick myself but I tore my groin muscle playing softball
over the weekend and that would be just too painful to attempt. ;-P
Since I have your attention (although you might be already out of the
office) I'm dying on another script - but this time trying to get it
working in IE (it works in Netscape fine.)
I stole some code from a script I used for form validation, which works
fine in both browsers (it's currently in production use.)
Here part of the code I borrowed:
...
var requiredFields = new Array("FirstName","LastName",
"Password","Verify","Address1","EmailAddress","City",
"DaytimePhone","StateOrProvince","Country","PostalCode","Username");
var fieldNames = new Array("First Name","Last Name",
"Password","Verify Password","Street Address",
"Email Address","City","Day Time Phone","State",
"Country","Postal Code","User Name");
...
for(var fieldNum=0; fieldNum < (requiredFields.length); fieldNum++) {
if ((input.elements[requiredFields[fieldNum]].value == "") ||
(input.elements[requiredFields[fieldNum]].value == " ") ||
(input.elements[requiredFields[fieldNum]].value == "NotSelected"))
{
fieldsNeeded += fieldNames[fieldNum] + "\n\t";
fieldCheck = false;
}
}
...etc...
This is what I transmografied it into:
var varDirection = true;
function PreSelectMajors(input) {
var majorsIDs = new Array('201','208','501');
var varCheck = true;
if (varCheck) {
for(var fieldNum=0; fieldNum < majorsIDs.length; fieldNum++) {
input.elements[majorsIDs[fieldNum]].checked = varDirection;
}
if (varDirection) {
varDirection = false;
} else {
varDirection = true;
}
}
}
Note: The majorsIDs array is created on the fly by ASP. Also if the array
is "blank", the ASP script will set varCheck to false, so the function
doesn't really do anything.
OK - This runs great with Netscape. IE throws an error on the line:
input.elements[majorsIDs[fieldNum]].checked = varDirection;
It says:
Error: 'elements[...]' is not an object.
What gives? I'd kick my machine out the window except my leg hurts too much.
---
Anthony Baratta
President
Keyboard Jockeys
Blatant Plug: Cool Jazz for a hot summer,
http://LisaMarie.Baratta.com
More information about the thelist
mailing list