JavaScript and client side scripting.
Moderator: General Moderators
patch2112
Forum Commoner
Posts: 86 Joined: Sun Oct 31, 2004 9:44 am
Location: London
Post
by patch2112 » Sun Feb 20, 2005 3:38 pm
Hello All,
I'm getting a "document.forms.form1[...] has no properties" error from the code below. The form is called form1 and it does exist later in the document, but shouldn't the color_checks() be called after the body loads? (via the run() function)
Any ideas? Any help would be greatly appreciated, still very new!
Philip
Code: Select all
<head>
<script type="text/javascript">
function color_checks( which )
{ document.forms.form1їwhich].checked = true;}
</script>
<script type="text/javascript">
function run()
{var exe = color_checks ('YellowB1'); }
</script>
</head>
<body onLoad="run()">
patch2112
Forum Commoner
Posts: 86 Joined: Sun Oct 31, 2004 9:44 am
Location: London
Post
by patch2112 » Sun Feb 20, 2005 3:40 pm
The reason I am splitting this into 2 functions is that the run() function is create by php with the appropriate values inserted.
Thanks again,
Philip
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 20, 2005 3:47 pm
document.forms['form1'].elements[which]
patch2112
Forum Commoner
Posts: 86 Joined: Sun Oct 31, 2004 9:44 am
Location: London
Post
by patch2112 » Sun Feb 20, 2005 3:54 pm
Thanks a bunch feyd!
That got it past the error, but I'm not sure how to make it check the checkbox now.
I tried...
document.forms['form1'].elements[which].checked = true;
document.forms['form1'].elements[which] = checked;
But neither worked
Thanks again,
Philip
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Feb 20, 2005 4:02 pm
Code: Select all
var buf = '';
var obj = document.formsї'form1'].elementsїwhich];
for(var i in obj)
{
buf += 'obj.' + i + ' = ' + objїi] + '\n';
}
alert(buf);should show you all properties and methods of the object... for debugging purposes..
patch2112
Forum Commoner
Posts: 86 Joined: Sun Oct 31, 2004 9:44 am
Location: London
Post
by patch2112 » Sun Feb 20, 2005 4:06 pm
I just got a blank alert box when I tried that. Isn't the proper code though...
Code: Select all
{ document.formsї'form1'].elementsїwhich].checked = true; }
Philip
patch2112
Forum Commoner
Posts: 86 Joined: Sun Oct 31, 2004 9:44 am
Location: London
Post
by patch2112 » Sun Feb 20, 2005 4:09 pm
There was a typo on the color name in the database. It's working like a charm now.
Thanks a lot feyd!
Philip