...

View Full Version : Javascript variable not displaying in specified form



Pojo
07-14-2005, 01:44 AM
Hello there, I have a problem with my JavaScript coding. Before you ask, I do know how to display the value of a variable in a form. I have in fact done it dozens of times, and have never had a problem with it. However, after beginning to create this document, I suddenly could not display a variable in a text input of a form. I have double and triple checked for spelling, formatting, and making sure that the variable is pointed to the right form, but still nothing. Help is appreciated.

(The form that the variable is pointing to is highlighted in blue)

Here is my document:


<html>
<head>
<title>
PictoQuest Battle Arena
</title>
<script language="javascript" type="text/javascript">
var characterpower = "10"
var characterdexterity = "10"
var charactertoughness = "10"
var characterwill = "10"
var characterintelligence = "10"
var characterlvl = "10"
var monsterpower = "10"
var monsterdexterity = "10"
var monstertoughness = "10"
var monsterwill = "10"
var monsterintelligence = "10"
var monsterlevel = "10"
</script>
</head>
<body>
<script language="javascript" type="text/javascript">
document.characterstats.characterlevelf.value= characterlvl;
</script>






<!--Begin Character Stats-->







<table border="0">
<tr>
<td>
<span style="font-weight:bold">Choose Your Character:</span>
</td>
<td>
<form name="characterlistf">
<select name="characterlist">
<option>[Default]</option>
</select>
</form>
</td>
<td>
Hp:
</td>
<td>
<form name="characterhpdisplay">
<input type="text" size="2" name="characterhpremaining" readonly="readonly">
/
<input type="text" size="2" name="characterhpmaximum" readonly="readonly">
</form>
</td>
<td>
Sp:
</td>
<td>
<form name="characterspdisplay">
<input type="text" size="2" name="characterspremaining" readonly="readonly">
/
<input type="text" size="2" name="charactersp maximum" readonly="readonly">
</form>
</td>
</tr>
</table>
<br />
<fieldset>
<legend>
Your Stats:
</legend>
<form name="characterstats">
Level:
<input type="text" size="2" name="characterlevelf" readonly="readonly">
Attribute:
<input type="text" name="characterattributef" readonly="readonly">
Weapon Style:
<input type="text" name="characterweaponstylef" readonly="readonly">
<br />
<br />
Power:
<input type="text" size="2" name="characterpowerf" readonly="readonly">
Dexterity:
<input type="text" size="2" name="characterdexterityf" readonly="readonly">
Toughness:
<input type="text" size="2" name="charactertoughnessf" readonly="readonly">
Will:
<input type="text" size="2" name="characterwillf" readonly="readonly">
Intelligence:
<input type="text" size="2" name="characterintelligencef" readonly="readonly">
</form>
</fieldset>
<table border="4" width="100%" cellpadding="4">
<tr>
<td width="25%">
<table brder="0">
<tr>
<td>
<span style="font-size:10; font-style:italic">
Chance:
</span>
<br />
<form name="characterbodysavef">
<input type="button" name="characterbodysaveb" value="Body Save">
</td>
</tr>
<tr>
<td>
<span style="font-size:10; font-style:italic">
Chance:
</span>
<br />
<form name="charactermindsavef">
<input type="button" name="charactermindsaveb" value="Mind Save">
</form>
</td>
</tr>
</table>
<td width="42%">
<table border="0" cellspacing="4">
<tr>
<td>
<span style="font-weight:bold">Type of Attack:</span>
<br />
<form name="characterattacktypef">
<input type="radio" name="charactertypeofattackr" value="charactertypeofattackrphysical">
Physical
<input type="radio" name="charactertypeofattackr" value="charactertypeofattackrspecial">
Special
<br />
Damage Ratio:
<input type="text" size="2" name="characterdamageratiot">
</form>
</td>
<td>
<span style="vertical-align:middle">
<form name="characterattackbuttonf">
<input type="button" name="characterattackbuttonb" value="Attack!">
</form>
</span>
</td>
</tr>
</table>
<td width="33%">
<form name="charactermovef">
<input type="button" name="charactermoveb" value="Move">
</form>
</td>
</tr>
</table>
<table border="0">
<tr>
<td>
<span style="font-style:italic">
Actions Remaining:
</span>
</td>
<td>
<form name="characteractionsf">
<input type="text" size="1" name="characteractionst" readonly="readonly">
</form>
</td>
</tr>
</table>
<br />
<hr />
<br />








<!--Begin Monster Stats-->



<table border="0">
<tr>
<td>
<span style="font-weight:bold">Choose Your Opponent:</span>
</td>
<td>
<form name="monsterlistf">
<select name="monsterlist">
<option>[Default]</option>
</select>
</form>
</td>
<td>
Hp:
</td>
<td>
<form name="monsterhpdisplay">
<input type="text" size="2" name="monsterhpremaining" readonly="readonly">
/
<input type="text" size="2" name="monsterhpmaximum" readonly="readonly">
</form>
</td>
<td>
Sp:
</td>
<td>
<form name="monsterspdisplay">
<input type="text" size="2" name="monsterspremaining" readonly="readonly">
/
<input type="text" size="2" name="monstersp maximum" readonly="readonly">
</form>
</td>
</tr>
</table>
<br />
<fieldset>
<legend>
Your Opponent's Stats:
</legend>
<form name="monsterstats">
Level:
<input type="text" size="2" name="monsterlevelf" readonly="readonly">
Attribute:
<input type="text" name="monsterattributef" readonly="readonly">
Weapon Style:
<input type="text" name="monsterweaponstylef" readonly="readonly">
<br />
<br />
Power:
<input type="text" size="2" name="monsterpowerf" readonly="readonly">
Dexterity:
<input type="text" size="2" name="monsterdexterityf" readonly="readonly">
Toughness:
<input type="text" size="2" name="monstertoughnessf" readonly="readonly">
Will:
<input type="text" size="2" name="monsterwillf" readonly="readonly">
Intelligence:
<input type="text" size="2" name="monsterintelligencef" readonly="readonly">
</form>
</fieldset>
<table border="4" width="100%" cellpadding="4">
<tr>
<td width="25%">
<table brder="0">
<tr>
<td>
<span style="font-size:10; font-style:italic">
Chance:
</span>
<br />
<form name="monsterbodysavef">
<input type="button" name="monsterbodysaveb" value="Body Save">
</td>
</tr>
<tr>
<td>
<span style="font-size:10; font-style:italic">
Chance:
</span>
<br />
<form name="monstermindsavef">
<input type="button" name="monstermindsaveb" value="Mind Save">
</form>
</td>
</tr>
</table>
<td width="42%">
<table border="0" cellspacing="4">
<tr>
<td>
<span style="font-weight:bold">Type of Attack:</span>
<br />
<form name="monsterattacktypef">
<input type="radio" name="monstertypeofattackr" value="monstertypeofattackrphysical">
Physical
<input type="radio" name="monstertypeofattackr" value="monstertypeofattackrspecial">
Special
<br />
Damage Ratio:
<input type="text" size="2" name="monsterdamageratiot">
</form>
</td>
<td>
<span style="vertical-align:middle">
<form name="monsterattackbuttonf">
<input type="button" name="monsterattackbuttonb" value="Attack!">
</form>
</span>
</td>
</tr>
</table>
<td width="33%">
<form name="monstermovef">
<input type="button" name="monstermoveb" value="Move">
</form>
</td>
</tr>
</table>
<table border="0">
<tr>
<td>
<span style="font-style:italic">
Actions Remaining:
</span>
</td>
<td>
<form name="monsteractionsf">
<input type="text" size="1" name="monsteractionst" readonly="readonly">
</form>
</td>
</tr>
</table>
</body>
</html>

As you can see, at the start of the document, there is a block of JavaScript defining multiple variables. Afer the body, there is another small block assigning a variable to a text input. If you look farther in the document, you can see this input and its form. Any ideas as to why this isn't showing up?

Thanks a lot! :)

sage45
07-14-2005, 02:29 AM
You have to assign the value after the form is created...
<html>
<head>
<title>
PictoQuest Battle Arena
</title>
</head>
<script language="javascript" type="text/javascript">
var characterpower = "10"
var characterdexterity = "10"
var charactertoughness = "10"
var characterwill = "10"
var characterintelligence = "10"
var characterlvl = "10"
var monsterpower = "10"
var monsterdexterity = "10"
var monstertoughness = "10"
var monsterwill = "10"
var monsterintelligence = "10"
var monsterlevel = "10"
</script>
<body>

...

<form name="characterstats">
Level:
<input type="text" size="2" name="characterlevelf" readonly="readonly">
Attribute:
<input type="text" name="characterattributef" readonly="readonly">
Weapon Style:
<input type="text" name="characterweaponstylef" readonly="readonly">
<br />
<br />
Power:
<input type="text" size="2" name="characterpowerf" readonly="readonly">
Dexterity:
<input type="text" size="2" name="characterdexterityf" readonly="readonly">
Toughness:
<input type="text" size="2" name="charactertoughnessf" readonly="readonly">
Will:
<input type="text" size="2" name="characterwillf" readonly="readonly">
Intelligence:
<input type="text" size="2" name="characterintelligencef" readonly="readonly">
</form>

<script language="javascript" type="text/javascript">
document.characterstats.characterlevelf.value= characterlvl;
</script>

...

</body>
</html>

HTH,

-sage-

Pojo
07-14-2005, 02:36 AM
Yes, I did that already. If you look near the top of the document, I have that exact line of code already inserted, right after the <body> tag. Thanks, though. :)

EDIT: I've figured it out. thanks for your help, it's fixed now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum