Inschrijfformulier met aantal wat leidt tot automatisch totaalbedrag

Status
Niet open voor verdere reacties.

jpjo

Nieuwe gebruiker
Lid geworden
23 jun 2014
Berichten
3
Hallo,

Ik heb een basic inschrijfformulier waarbij de gegegevens in een mysql database wordt opgeslagen.
Met het inschrijfformulier kan de bezoeker een product aanvragen. Nu hebben ze de mogelijkheid om meerdere
producten aan te vragen. Het inschrijfformulier ziet er als volgt uit:
HTML:
<input type="checkbox" name="machtiging" style="width:20px;height:20px;margin-left:-38px;margin-top:-2px;" />
                      <br style="clear:both;" /><br />
						<input type="text" name="issue" style="width:230px;margin-left:-305px;margin-top:-45px;" /><br />
						<input type="text" name="aantal" style="width:230px;margin-left:-305px;margin-top:36px;" /><br />
						<input type="text" name="totaal" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
						<input type="text" name="rekeningnummer" style="width:230px;margin-left:-10px;margin-top:-20px;" /><br />
						<input type="text" name="voornaam" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="checkbox" name="nieuwsbrief" style="width:20px;height:20px;margin-left:-38px;margin-top:-10px;" /><br style="clear:both;" /><br />	
						<input type="text" name="achternaam" style="width:230px;margin-left:-305px;margin-top:-28px;" /><br />					
                                                <input type="checkbox" name="aanbieding" style="width:20px;height:20px;margin-left:-38px;margin-top:1px;" /><br style="clear:both;" />
                                                <input type="text" name="straat" style="width:230px;margin-left:-305px;margin-top:-19px;" /><br />
                                                <input type="text" name="huisnummer" style="width:80px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="postcode" style="width:80px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="stad" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="geboortedatum" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="email" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
						<input type="submit" value="" style="margin-top:20px;margin-left:95px;width:126px;height:31px;cursor:pointer;" />

De basics heb ik enigzins door, maar nu wordt het voor mij lastig. Zoals je kan zien kan de bezoeker het 'aantal' aangeven. Het zou fantastisch zijn als er dan
automatisch bij 'totaal' het totaalbedrag komt te staan. Dus als ze 1 intoetsen dan krijg je 19,95. Bij 2 wordt het dan 39,90.

Ik hoop dat iemand mij kan helpen om dit script te realiseren.

Alvast bedankt
 
Laatst bewerkt door een moderator:
PHP is reactief op pagina niveau. Als je interactief wil, zal je richting javascript gaan.

graag ook HTML tags om je code plakken anders is het bijna onleesbaar
 
Hallo,

Bijgaand nu ook met HTML Tags. Heb je enig idee hoe ik dat het beste kan doen?
PHP:
<html>
<head>

	<style>
		body { padding:0; margin:0; }
		img { border: 0; }
		input { width:226px; border:0; background-color:transparent;line-height:20px;height:20px; }
	</style>

	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

</head>
<body>
			<?php 
			
						mysql_query('INSERT INTO `inschrijving` (machtiging, issue, aantal, totaal, rekeningnummer, voornaam, nieuwsbrief, achternaam, aanbieding, straat, huisnummer, postcode, stad, geboortedatum, email, campaign) VALUES ("'.$machtiging.'", "'.mysql_real_escape_string($_POST['issue']).'", "'.mysql_real_escape_string($_POST['aantal']).'", "'.mysql_real_escape_string($_POST['totaal']).'", "'.mysql_real_escape_string($_POST['rekeningnummer']).'", "'.mysql_real_escape_string($_POST['voornaam']).'", "'.$nieuwsbrief.'", "'.mysql_real_escape_string($_POST['achternaam']).'", "'.$aanbiedingen.'", "'.mysql_real_escape_string($_POST['straat']).'", "'.mysql_real_escape_string($_POST['huisnummer']).'", "'.mysql_real_escape_string($_POST['postcode']).'", "'.mysql_real_escape_string($_POST['stad']).'", "'.mysql_real_escape_string($_POST['geboortedatum']).'", "'.mysql_real_escape_string($_POST['email']).'", "'.mysql_real_escape_string($_GET['campaign']).'");') or die('query mislukt');
				
			?>
<form method="POST">
				          
				<?php
				?>
				<div style="width:695px;height:484px;background-image:url(index/bflbag.png);">
					<div style="padding-left:445px;padding-top:67px;">
                                                <input type="checkbox" name="machtiging" style="width:20px;height:20px;margin-left:-38px;margin-top:-2px;" /><br style="clear:both;" /><br />
						<input type="text" name="issue" style="width:230px;margin-left:-305px;margin-top:-45px;" /><br />
						<input type="text" name="aantal" style="width:230px;margin-left:-305px;margin-top:36px;" /><br />
						<input type="text" name="totaal" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
						<input type="text" name="rekeningnummer" style="width:230px;margin-left:-10px;margin-top:-20px;" /><br />
						<input type="text" name="voornaam" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="checkbox" name="nieuwsbrief" style="width:20px;height:20px;margin-left:-38px;margin-top:-10px;" /><br style="clear:both;" /><br />	
						<input type="text" name="achternaam" style="width:230px;margin-left:-305px;margin-top:-28px;" /><br />					
                                                <input type="checkbox" name="aanbieding" style="width:20px;height:20px;margin-left:-38px;margin-top:1px;" /><br style="clear:both;" />
                                                <input type="text" name="straat" style="width:230px;margin-left:-305px;margin-top:-19px;" /><br />
                                                <input type="text" name="huisnummer" style="width:80px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="postcode" style="width:80px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="stad" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="geboortedatum" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
                                                <input type="text" name="email" style="width:230px;margin-left:-305px;margin-top:8px;" /><br />
						<input type="submit" value="" style="margin-top:20px;margin-left:95px;width:126px;height:31px;cursor:pointer;" />
					</div>

				</div>
				
</form>


</body>
</html>
 
Laatst bewerkt door een moderator:
Beste jpjo,

Voor het plaatsen van code kun je gebruik maken van de BB Codes
HTML:
...
en
PHP:
...
, dit maakt het voor een ander leesbaarder ;)
 
PHP:
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Mijn title</title>
		<style type="text/css">
        	body { padding:0; margin:0; }
            img { border: 0; }
            input { width:226px; border:0; background-color:transparent;line-height:20px;height:20px; }
		</style>
		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
		<script type="text/javascript">
			function updateAantal(input) {
				$("#aantal").html('Bedrag: ' + parseFloat($(input).val() * 19.95));
			}
		</script>
	</head>
	<body>
		<!--....-->
		<?php
		if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['issue'], $_POST['aantal'] /* Etc */)) {
			/* Maak gebruik van MySQLi of PDO */
			if(mysql_query('INSERT INTO `inschrijving` (machtiging, issue, aantal, totaal, rekeningnummer, voornaam, nieuwsbrief, achternaam, aanbieding, straat, huisnummer, postcode, stad, geboortedatum, email, campaign) VALUES ("'.$machtiging.'", "'.mysql_real_escape_string($_POST['issue']).'", "'.mysql_real_escape_string($_POST['aantal']).'", "'.mysql_real_escape_string($_POST['totaal']).'", "'.mysql_real_escape_string($_POST['rekeningnummer']).'", "'.mysql_real_escape_string($_POST['voornaam']).'", "'.$nieuwsbrief.'", "'.mysql_real_escape_string($_POST['achternaam']).'", "'.$aanbiedingen.'", "'.mysql_real_escape_string($_POST['straat']).'", "'.mysql_real_escape_string($_POST['huisnummer']).'", "'.mysql_real_escape_string($_POST['postcode']).'", "'.mysql_real_escape_string($_POST['stad']).'", "'.mysql_real_escape_string($_POST['geboortedatum']).'", "'.mysql_real_escape_string($_POST['email']).'", "'.mysql_real_escape_string($_GET['campaign']).'");')) {
				echo "Geluk!";
			} else {
				echo "Oeps, query mislukt!"; /* Geen die(), jij gaat ook niet dood als je iets fout doet */
			}
		}
		?>

		<form action="#" method="POST">
			<input onchange="updateAantal(this)" type="number" name="quantity" value="1" min="1" max="5">
			<!-- Etc -->	
		</form>
		<p id="aantal">Bedrag: 19,95</p>
		<!--....-->
	</body>
</html>

Je zou zelf nog even moeten uitzoeken hoe je dit in euro`s krijgt.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan