Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 21-07-2009
Join Date: Jul 2009
Posts: 1
question Help With Serveral Functions in Javascript

I have a form that the user will input three fields: body, mind, and soul. I want the functions to calculate the health, energy, acv1, and dcv1 and put those values into the fields in the form for the user to see as well as to be submitted in the form. Here is my form:

HTML Code:
<form action="testfunction.php" method="post">
<table border="0">
    <td><input type="text" onKeyUp="handle('body','soul','health')" name="body" size="10" maxlength="2"></td>

    <td><input type="text" onKeyUp="handle('mind','soul','energy')" name="mind" size="10" maxlength="2"></td>
    <td><input type="text" onKeyUp="handle('body','soul','health')" name="soul" size="10" maxlength="2"></td>

    <td>Health Points:</td>
    <td><input type="text" onKeyUp="handle('body','soul')"
 name="health" size="10" maxlength="3" disabled="true" /></td>
    <td>Energy Points:</td>
    <td><input type="text" onKeyUp="handle('mind','soul')" name="energy" size="10" maxlength="3" disabled="true" /></td>
    <td>Attack Combat Value:</td>

    <td><input type="text" name="acv1" size="10" maxlength="3" disabled="true" /> </td>
    <td>(Special Attack)</td>
    <td><input type="text" name="acv2" size="10" maxlength="3" disabled="true" /> </td>

    <td>Defense Combat Value:</td>
    <td><input type="text" name="dcv1" size="10" maxlength="30" disabled="true" /> </td>
    <td>(Special Defense)</td>
    <td><input type="text" name="dcv2" size="10" maxlength="3" disabled="true" /> </td>
    <td>Total Character Points:</td>
    <td><input type="text" name="total_cp" size="10" maxlength="3" value="10" disabled="true" /> </td>
<p style="text-align: center" class="submit"><input type="submit" value="Create Character" />
<input type="reset" value="Reset" /></p>

The calculations I need are as follows:

Health - [(Body+Soul)x5]
Energy - [(Mind+Soul)x5]
ACV1 - [(Body+Mind+Soul)/3] (floored)
DCV1 - [(Body+Mind+Soul)/3] (floored) - 2

Can someone help me on how I would write these functions? Someone was helping me with two of the functions, but they were unable to help with the last two functions, and I am unable to understand how I can alter the function they wrote. Here is the function they provided:

<script type="text/javascript">
function handle(a,b,c) {
var e = document.getElementsByTagName('input');
for (i in e) {
if (e[i].name == a) a = e[i];
if (e[i].name == b) b = e[i];
if (e[i].name == c) c = e[i];
c.value = (Number(a.value) + Number(b.value)) * 5;


Can this script be altered to work with my other two values needed, ACV1 AND DCV1? Or do I need to write a completely new function that would work with all four? Can someone help me out with these functions? I am COMPLETELY new to JavaScript and I have written functions in PHP, but I need them to display the values in the form when the user types in the other three, and with PHP, I can only save them or display them on another page after the form is submitted. Or I probably could have the form action set to itself, btu I'm not sure how I would display the results in the form fields. It seems JavaScript would be the easiest int his situation. Can anyone help? Please?
Reply With Quote

  TechArena Community > Software > Software Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Help With Serveral Functions in Javascript"
Thread Thread Starter Forum Replies Last Post
Components and functions of UML NatureAddicted Software Development 6 22-02-2011 03:47 PM
Can I Define and Call my Own Functions in JavaScript? Rob Dizzle Software Development 5 09-02-2010 05:18 AM
How to launch JavaScript functions in PDF Abhimanyusuta Software Development 5 14-01-2010 04:04 AM
Functions in PHP Gyan Guru Guides & Tutorials 3 13-12-2008 06:20 PM
Functions in Excel Stephanatic Windows Software 3 04-10-2008 12:40 PM

All times are GMT +5.5. The time now is 05:38 AM.