Jump to content

a form that multiply


arn_php

Recommended Posts

Hi there, need any help on figuring how to make this work.  I am making a registration form where it has up to 4 registrar's name fields.  And there is a registration fee that filled with a certain amount for each registrar.  I am trying to figure it out how to make a total field for the total registration fee where when you fill in each name field, the total field would automatically count each registrar.

 

Here is the form code:

(the reg fee is coming from a database, the total should count it all as the registrar being filled)

 

<table width="100%" border="0" cellspacing="0" cellpadding="5">

  <tr>

    <td><strong><font size="3"> Conferees:</font></strong></td>

    <td><strong><font size="3"> Names</font></strong></td>

    <td><strong><font size="3"> Last Names</font></strong></td>

    <td><strong><font size="3"> Badge Name</font></strong></td>

  </tr>

  <tr>

    <td><label <?=($error['first_name1'] != '')?'class="error"':'';?>><strong><font size="3">

      Conferee 1</font></strong> <span class="error">*</span></label></td>

    <td><input <?php mOver('ov') ?> type="text" name="first_name1" size="15" value="<?=stripslashes($_POST['first_name1']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="last_name1" size="15" value="<?=stripslashes($_POST['last_name1']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="badge_name1" size="15" value="<?=stripslashes($_POST['badge_name1']);?>" /></td>

  </tr>

  <tr>

    <td><strong><font size="3"> Conferee 2</font></strong></td>

    <td><input <?php mOver('ov') ?> type="text" name="first_name2" size="15" value="<?=stripslashes($_POST['first_name2']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="last_name2" size="15" value="<?=stripslashes($_POST['last_name2']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="badge_name2" size="15" value="<?=stripslashes($_POST['badge_name2']);?>" /></td>

  </tr>

  <tr>

    <td><strong><font size="3"> Conferee 3</font></strong></td>

    <td><input <?php mOver('ov') ?> type="text" name="first_name3" size="15" value="<?=stripslashes($_POST['first_name3']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="last_name3" size="15" value="<?=stripslashes($_POST['last_name3']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="badge_name3" size="15" value="<?=stripslashes($_POST['badge_name3']);?>" /></td>

  </tr>

  <tr>

    <td><strong><font size="3"> Conferee 4</font></strong></td>

    <td><input <?php mOver('ov') ?> type="text" name="first_name4" size="15" value="<?=stripslashes($_POST['first_name4']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="last_name4" size="15" value="<?=stripslashes($_POST['last_name4']);?>" /></td>

    <td><input <?php mOver('ov') ?> type="text" name="badge_name4" size="15" value="<?=stripslashes($_POST['badge_name4']);?>" /></td>

  </tr>

</table>

<table width="100%" border="0" cellpadding="5" cellspacing="0">

  <tr>

    <td width="40%"><div align="right">

        <label <?=($error['reg_fee'] != '')?'class="error"':'';?>><strong>Registration

        Fee: <span class="error">*</span></strong></label>

      </div></td>

    <td>$US

      <input <?php mOver('ov') ?> type="text" name="reg_fee" size="50" value="<?php $query="SELECT * FROM specialm_confe WHERE confe_id='$id' LIMIT 1";

$result=mysql_query($query);

while($row=mysql_fetch_array($result))

{ echo ''.stripslashes($row['harga']).''; } ?>" /></td>

  </tr>

  <tr>

    <td width="40%"><div align="right">

        <label <?=($error['total_fee'] != '')?'class="error"':'';?>><strong>TOTAL:

        <span class="error">*</span></strong></label>

      </div></td>

    <td>$US

      <input <?php mOver('ov') ?> type="text" name="total_fee" size="15" value="<?=stripslashes($_POST['total_fee']);?>" /></td>

  </tr>

</table>

<div align="center">

  <input name="Submit" type="submit" value="Submit" class="button1" onmouseover="this.className='button1Ov'" onmouseout="this.className='button1'" />

</div>

 

Link to comment
Share on other sites

To save you the hassel of trying to use php for this, you want to use Javascript.

 

I would suggest looking there. Since PHP is a server-side script it cannot be changed after it has been processed, that is where the javascript comes into play.

Link to comment
Share on other sites

Hi,

 

You would need to give each name a class like names an id with an incrementing value like name1, name2 etc. Then you would want a function in the head that is something like:

 

set total =0, search dom tree to put all elements with class=names in an array then do for (var i in namesarray) {

  total = namesarray.value + total

}

getElementById('total').value=total

 

Martin

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.