Page 1 of 1

[SOLVED] No Properties?

Posted: Sun Feb 20, 2005 3:38 pm
by patch2112
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 )
&#123; document.forms.form1&#1111;which].checked = true;&#125;
</script>

<script type="text/javascript">
function run()
&#123;var exe = color_checks ('YellowB1'); &#125; 
</script>

</head>

<body onLoad="run()">

oh yeah

Posted: Sun Feb 20, 2005 3:40 pm
by patch2112
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

Posted: Sun Feb 20, 2005 3:47 pm
by feyd
document.forms['form1'].elements[which]

Posted: Sun Feb 20, 2005 3:54 pm
by patch2112
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

Posted: Sun Feb 20, 2005 4:02 pm
by feyd

Code: Select all

var buf = '';
var obj = document.forms&#1111;'form1'].elements&#1111;which];
for(var i in obj)
&#123;
  buf += 'obj.' + i + ' = ' + obj&#1111;i] + '\n';
&#125;
alert(buf);
should show you all properties and methods of the object... for debugging purposes.. :)

thanks again

Posted: Sun Feb 20, 2005 4:06 pm
by patch2112
I just got a blank alert box when I tried that. Isn't the proper code though...

Code: Select all

&#123; document.forms&#1111;'form1'].elements&#1111;which].checked = true; &#125;
Philip

Got it!

Posted: Sun Feb 20, 2005 4:09 pm
by patch2112
There was a typo on the color name in the database. It's working like a charm now.

Thanks a lot feyd!
Philip