Jump to content

If Statement Help


twilitegxa

Recommended Posts

I have the following script:

 

<?php

session_start();

?>
<form>
<table cellpadding="3" cellspacing="3">
<tr>
<th>Attribute</th>
<th>Level</th>
<th>Power Points:</th>
<th>Character Points:</th>
</tr>
<tr>
<td><input type="text" readonly="readonly" value="Scout/Knight Powers" size="19" name="attribute1" /></td>
<td><select name="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>
<td align="center"><input type="text" name="cp_remain" id="cp_remain" size="1" readonly="readonly" /></td>
</tr>
</table>
</form>

<form method="POST" action="test_batosai.php">
    <table><tr><td>
     <div id="dynamicInput1">
            <table cellpadding="3" cellspacing="3">
            <thead>
            <tr>
            <th>Sub-Attribute</th>
            <th>Level</th>
            <th>Notes <i>(optional)</i></th>
            </tr>
            </thead>
            <tbody>
            <tr>
            <td>
            <select name="attribute[]" size="1">
            <option value="1">Animal Guardian</option>
            <option value="2">Combined Attacks</option>
            <option value="3">Elemental Control</option>
            <option value="4">Emotional Control</option>
            <option value="5">Item Of Power</option>
            <option value="6">Knight Attack</option>
            <option value="7">Rejuvenation</option>
            <option value="8">Sailor Scout Attack</option>
            </select></td>
            <td>
            <select name="attribute_level[]">
            <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><textarea name="sub_notes[]" rows="1" cols="30">
            </textarea></td>
            </tr>
            </tbody>
            </table>
     </div>
     <div id="cloneDiv1">
     
     </div>
     </td>
     <td>
     <div id="dynamicInput2">
        <table cellpadding="3" cellspacing="3">
        <thead>
        <tr>
        <th>Neutral Attribute</th>
        <th>Level</th>
         <th>Notes <i>(optional)</i></th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td>
        <select name="attribute2[]" size="1">
        <option value="1">Acrobatics</option>
        <option value="2">Appearance</option>
        <option value="3">Art Of Distraction</option>
        <option value="4">Combat Mastery</option>
        <option value="5">Damn Healthy!</option>
        <option value="6">Divine Relationship</option>
        <option value="7">Energy Bonus</option>
        <option value="8">Extra Attacks</option>
        <option value="9">Focused Combat</option>
        <option value="10">Fortified Body</option>
        <option value="11">Heightened Negaverse Power</option>
        <option value="12">Heightened Senses</option>
        <option value="13">Heightened Scout Powers</option>
        <option value="14">Massive Damage</option>
        <option value="15">Powerful Mind</option>
        <option value="16">Special Attack/Defense</option>
        <option value="17">Speed</option>
        <option value="18">Strong Soul</option>
        <option value="19">Supernatural Training</option>
        <option value="20">Unique Character Attribute</option>
        </select></td>
        <td>
        <select name="attribute_level2[]">
        <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><textarea name="neutral_notes[]" rows="1" cols="30">
            </textarea></td>
        </tr>
        </tbody>
        </table>
    </div>
    <div id="cloneDiv2">
    </div>
</td></tr></table>
     <input type="button" value="Add another Sub-Attribute" onClick="addInput('dynamicInput1','cloneDiv1');">
     <input type="button" value="Add another Neutral Attribute" onClick="addInput('dynamicInput2','cloneDiv2');">
     <input type="submit" /><input type="reset" />
</form>
<script type="text/javascript">
var counter = 1;
var limit = 10000000;// Set a limit if you want to
function addInput(divFrom,divTo){
     if (counter == limit)  {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else {
          var newdiv = document.createElement('div');
          newdiv.innerHTML =  document.getElementById(divFrom).innerHTML;
          document.getElementById(divTo).appendChild(newdiv);
          counter++;
     }
}

//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].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].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
</script>

 

How can I write a JavaScript that will update the power_points field if the sub-attribute is chosen? Like:

 

if animal guardian is chosen

      Power_points - (attribute_level * 1)

if combined attacks is chosen

      power_points - (attribute_level * 1)

if elemental control is chosen

      power_points - (attribute_level * 3)

etc...

 

Can anyone help?

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.