arn_php Posted December 5, 2008 Share Posted December 5, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/135638-a-form-that-multiply/ Share on other sites More sharing options...
premiso Posted December 5, 2008 Share Posted December 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135638-a-form-that-multiply/#findComment-706832 Share on other sites More sharing options...
arn_php Posted December 6, 2008 Author Share Posted December 6, 2008 If I use javascript, how would that be? Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/135638-a-form-that-multiply/#findComment-707236 Share on other sites More sharing options...
msinternet Posted December 10, 2008 Share Posted December 10, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135638-a-form-that-multiply/#findComment-711801 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.