...

View Full Version : 'Object doesn't support this property or method' Help Please



tenniskid493
01-29-2006, 12:06 AM
Help, I'm making an online battle game and am currently making the text version just to get the equations working. I keep getting this error:
http://i24.photobucket.com/albums/c25/tenniskid493/608fcb0c.jpg

I can't seem to find what the error is. Can anyone help me. Here's my code:


<html>
<head>
<script type="text/javascript">
var name=document.player.name.value;
var element=document.player.element.value;
var level=document.player.level.value;
var health=document.player.health.value;
var magic=document.player.magic.value;
var speed=document.player.speed.value;
var attack=document.player.attack.value;
var defense=document.player.defense.value;
var name1=document.enemy.name.value;
var element1=document.enemy.element.value;
var level1=document.enemy.level.value;
var health1=document.enemy.health.value;
var magic1=document.enemy.magic.value;
var speed1=document.enemy.speed.value;
var attack1=document.enemy.attack.value;
var defense1=document.enemy.defense.value;
function attack()
{
document.enemy.health.value=parseInt(health1)-10;
}
</script>
</head>
<body>
<table><tr><td><form name="player">
Name <input type="text" size="20" name="name" value="Brian"><br>
Element <input type="text" size="20" name="element" value="Fire"><br>
Level <input type="text" size="20" name="level" value="25"><br><br>
Health <input type="text" size="20" name="health" value="500"><br>
Magic <input type="text" size="20" name="magic" value="250"><br>
Speed <input type="text" size="20" name="speed" value="100"><br>
Attack <input type="text" size="20" name="attack" value="125"><br>
Defense <input type="text" size="20" name="defense" value="115"><br>
</form></td><td><form name="enemy">
Name <input type="text" size="20" name="name" value="Enemy"><br>
Element <input type="text" size="20" name="element" value="Water"><br>
Level <input type="text" size="20" name="level" value="23"><br><br>
Health <input type="text" size="20" name="health" value="465"><br>
Magic <input type="text" size="20" name="magic" value="285"><br>
Speed <input type="text" size="20" name="speed" value="85"><br>
Attack <input type="text" size="20" name="attack" value="105"><br>
Defense <input type="text" size="20" name="defense" value="100"><br>
</td></tr></table>
<input type="button" value="Attack" onclick="attack()">
<input type="button" value="Defend" onclick="defend()">
<input type="button" value="Fireball" onclick="fireball()">
<input type="button" value="Lightning" onclick="lightning()">
<input type="button" value="Heal" onclick="heal()">
</body></html>

MetalStorm
01-29-2006, 12:49 AM
Well, it's doing var name=document.player.name.value; before the form has been created (before it in the page), so it doesn't exist therefor has no properites.

Leave the variable declarations where they are but initialise them inside a function that you can call onload.

tenniskid493
01-29-2006, 12:51 AM
Thats one problem, but that still doesn't fix that error message.

liorean
01-29-2006, 01:17 AM
You need to delay all those assignments to after the form has been parsed. So, move them into the load event.

tenniskid493
01-29-2006, 02:19 AM
Thanx guys, you helped me out. The one thing I changed is used id instead of name and it fixed everything. (not my idea, suggested by someone else)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum