php/js form return total value

General discussions related to php

Moderators: egami, macek, gesf

Post Reply

Mon Oct 29, 2012 7:08 am

i have a form which adds the cost of various items, the total is calculated in the field called "total"
When the submit button is pressed, the form fades out and a success message appears.
So far so good, what i need is for the total field and it's value to re-appear alongside the success message.
I have tried lots of ways but i can't get it to work, thanks for your help!

HTML code:

<script type="text/javascript">
function checkTotal() { = '';
var sum = 0;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice.checked) {
sum = sum + parseInt(document.listForm.choice.value);
} = sum;

<form id="contactForm" name="listForm" action="#" method="post"><fieldset>

<input type="checkbox" id="A12 SS MER 19H30 CAS" name="choice" value="260" onchange="checkTotal()"class="form-poshytip" title="Cochez ici" />
<label>Mercredi 19h30 à 22h, niveaux 1,2,3</label>

<input type="checkbox" id="A12 SS JEU 19H30 CAS" name="choice" value="360" onchange="checkTotal()"class="form-poshytip" title="Cochez ici" />
<label>Jeudi 19h30 à 22h, niveaux 1,2,3</label><br/>

<td><p class="texte_courant">Total : $<input type="text" size="2" name="total" value="0"/> taxes incluses </p> </td></tr>

<p><input type="button" value="Envoyez" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
</td></tr></table> </fieldset>

<p id="success" class="success">Nous avons bien reçu votre message, merci:) </p>



function success(){


New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Mon Oct 29, 2012 10:43 pm

To send a Javascript value to PHP you'd need to use AJAX. With jQuery, it would look something like this:
var variableToSend = 'foo';
$.post('file.php', {variable: variableToSend});

On your server, you would need to receive the variable sent in the post:
$variable = $_POST['variable'];

Post Reply