Jump to content

If Statement help


twilitegxa

Recommended Posts

Is there a way to write some if statements that will name a variable based on what option a user selects in the options?

 

I have the following 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=10-((first)*4);
//show the result in the result textbox
document.forms[1].cp_remain.value=res2;
}
//end function for Character 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>

 

For example, in the first set of select options (starting with Animal Guardian), I would need to write an if statement something like this:

 

if select option from attribute = animal guardian {

$guardian = (attribute_level * 1)

}

 

I know that syntax isn't exactly right, but just to give you an idea of how I need to write it. I need to take the first option, and if they choose it, then take the second option value, and multiply it by a specific amount (in this case 1, but ill be other numbers in other cases), and then set that to a variable name so it can be used in a function or something later on the page. Can anyone help me write this properly?

Link to comment
https://forums.phpfreaks.com/topic/168230-if-statement-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.