[SOLVED] No Properties?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

[SOLVED] No Properties?

Post 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()">
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

oh yeah

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

document.forms['form1'].elements[which]
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.. :)
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

thanks again

Post 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
patch2112
Forum Commoner
Posts: 86
Joined: Sun Oct 31, 2004 9:44 am
Location: London

Got it!

Post 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
Post Reply