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
https://forums.phpfreaks.com/topic/135638-a-form-that-multiply/
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
https://forums.phpfreaks.com/topic/135638-a-form-that-multiply/#findComment-711801
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.