Jump to content

[SOLVED] Second Function Won't Work


twilitegxa

Recommended Posts

I have a second function:

 

//function for Character Points remaining
function remain()
{
var first,res2;
//Take the value of first textbox and convert it to float
first=parseFloat(document.forms[0].attribute_level.value);
res2=10-((first)*4);
//show the result in the result textbox
document.forms[0].cp_remain.value=res2;
}
//end function for Character Points

 

But I can't figure out why it isn't working. Can anyone help? Here is the full page:

 

<?php

session_start();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sailor Moon RPG - Character Creation Form | Scout</title>
<script type="text/javascript">

//function for adding Sub-Attribute
function addRowClone(tblId)
{
  var tblBody = document.getElementById(tblId).tBodies[0];
  var newNode = tblBody.rows[0].cloneNode(true);
  tblBody.appendChild(newNode);
}
//end function for Sub-Attribute

//function for adding Neutral Attributes
function addRowClone(tblId)
{
  var tblBody = document.getElementById(tblId).tBodies[0];
  var newNode = tblBody.rows[0].cloneNode(true);
  tblBody.appendChild(newNode);
}
//end function for Neutral Attributes

//function for Power Points
function power()
{
var first,res1;
//Take the value of first textbox and convert it to float
first=parseFloat(document.forms[0].attribute_level.value);
res1=(first)*10;
//show the result in the result textbox
document.forms[0].power_points.value=res1;
}
//end function for Power Points

//function for Character Points remaining
function remain()
{
var first,res2;
//Take the value of first textbox and convert it to float
first=parseFloat(document.forms[0].attribute_level.value);
res2=(first)*4;
//show the result in the result textbox
document.forms[0].cp_remain.value=res2;
}
//end function for Power Points

</script>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Chapter 2: Character Creation</h1>
<table cellpadding="3" cellspacing="3">
<tr>
<td valign="top" width="60%"><h2>Scout/Knight Sub-Attributes</h2>
<form>
<table cellpadding="3" cellspacing="3">
<thead>
<tr>
<th>Attribute</th>
<th>Level</th>
<th>Power Points:</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" readonly="readonly" value="Scout/Knight Attribute" size="19" name="attribute" /></td>
<td>
<select name="attribute_level" onclick="power(), remain()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select></td>
<td align="center"><input type="text" name="power_points" id="power_points" size="1" readonly="readonly"/></td>
</tr>
</tbody>
</table>
<br />

<table id="tblClone" cellpadding="3" cellspacing="3">
<thead>
<tr>
<th>Sub-Attribute</th>
<th>Level</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select name="attribute" size="1">
<option value="Animal Guardian">Animal Guardian</option>
<option value="Elemental Control">Elemental Control</option>
<option value="Item Of Power">Item Of Power</option>
<option value="Rejuvenation">Rejuvenation</option>
<option value="Combined Attacks">Combined Attacks</option>
<option value="Emotional Control">Emotional Control</option>
<option value="Knight Attack">Knight Attack</option>
<option value="Sailor Scout Attack">Sailor Scout Attack</option>
</select></td>
<td>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select></td>
</tr>
</tbody>
</table><br />
<input type="button" class="add, sub_tab" value="Add Sub-Attribute" onclick="addRowClone('tblClone');" />
</form></td>
<td valign="top"><h2>Neutral Attributes</h2>
<form>
  <table width="274" cellpadding="3" cellspacing="3">
    <thead>
      <tr>
      <th> </th>
      <th align="right">Character Points:</th>
      <th><input type="text" name="cp_remain" id="cp_remain" size="1" readonly="readonly" /></th>
      </tr>
      <tr>
      <td> </td>
        <td> </td>
        <td></td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td> </td>
        <td> </td>
        <td></td>
      </tr>
    </tbody>
  </table>

<table id="tblClone2" cellpadding="3" cellspacing="3">
<thead>
<tr>
<th>Attribute</th>
<th>Level</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select name="attribute" size="1">
<option value="Acrobatics">Acrobatics</option>
<option value="Appearance">Appearance</option>
<option value="Art Of Distraction">Art Of Distraction</option>
<option value="Combat Mastery">Combat Mastery</option>
<option value="Damn Healthy!">Damn Healthy!</option>
<option value="Divine Relationship">Divine Relationship</option>
<option value="Energy Bonus">Energy Bonus</option>
<option value="Extra Attacks">Extra Attacks</option>
<option value="Focused Combat">Focused Combat</option>
<option value="Fortified Body">Fortified Body</option>
<option value="Heightened Negaverse Power">Heightened Negaverse Power</option>
<option value="Heightened Senses">Heightened Senses</option>
<option value="Heightened Scout Powers">Heightened Scout Powers</option>
<option value="Massive Damage">Massive Damage</option>
<option value="Powerful Mind">Powerful Mind</option>
<option value="Special Attack/Defense">Special Attack/Defense</option>
<option value="Speed">Speed</option>
<option value="Strong Soul">Strong Soul</option>
<option value="Supernatural Training">Supernatural Training</option>
<option value="Unique Character Attribute">Unique Character Attribute</option>
</select></td>
<td>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select></td>
</tr>
</tbody>
</table><br />
<input type="button" class="add, neutral_tab" value="Add Attribute" onclick="addRowClone('tblClone2');" />
</form></td>
</tr>
</table>

</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

Link to comment
Share on other sites

edit: removed my false comment, replaced it with this....

 

the following line is referencing the first form in the document (forms[0]) ... should be forms[1], cause the form element is in the second form...

 

document.forms[0].cp_remain.value=res2;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.