I've been trying some stuff out and I came accross a problem. I want to use a variable that will replace an object's name in a onClick command on a button. The variable is text entered in a text filed. How would I go about doing this?
here is my script:
here is my script:
Code:
<script> var gordon = new hlguy("Gordon", "100", "100", "AR"); function hlguy(name, health, armor, weapon) { this.name=name; this.health=health; this.armor= armor; this.weapon=weapon; this.display = display; this.hurt1hp= hurt1hp; this.hurt2hp= hurt2hp; this.hurt3hp= hurt3hp; } function createnewhlguy() { newguystring= " "; var thenewname = document.hl.playername.value var createit = new hlguy(thenewname, "100", "100", "AR"); var thenewname = createit newguystring = "Name: " + thenewname.name + " Health: " + thenewname.health; document.hl.status.value = newguystring } function hurt1hp(namee) { this.health = this.health - 1 return namee.health } function hurt2hp() { this.health = this.health - 2 this.display() } function hurt3hp() { this.health = this.health - 3 this.display() } function display() { var the_string = ""; var min_health = 0 if (this.health < min_health) { the_string = this.name + " IS DEAD!"; } else { the_string += "Name: " + this.name + " Health: " + this.health; } window.document.hl.status.value = the_string; } var nametext = document.hl.playername.value </script> <form name="hl"> Enter the Player's Name: <input type="text" name="playername" size="30" value="Name"><br> Status of the Player: <input type="text" name="status" size="50" ><br> <input type="button" value="Create the new Player" onClick="createnewhlguy();"><br> <input type="button" value="-1 HP" onClick="hurt1hp(nametext);"><br> <input type="button" value="-2 HP" onClick="nametext.hurt2hp();"><br> <input type="button" value="-3 HP" onClick="nametext.hurt3hp();"><br> </form> <script> </script>
Comment