Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'Object doesn't support this property or method' Help Please

    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:


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

    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>

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats one problem, but that still doesn't fix that error message.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    You need to delay all those assignments to after the form has been parsed. So, move them into the load event.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •