Hey, as the title says i need some help. I currently have a contact form ( self made). Easiest way to explain.
I have a form : http://martinlougas.eu/pood.html . Problem is that on the right side the checkboxes, once you check them the price (shown after the name) has to display in a box under "Summa". Currently it is only showing when all of the boxes are checked. ( Yes i know that one is selected by default, it has to be and it has to be not "deselectable" . After the price displaying is okay, it should send it to certain email with all the info ( boxes) selected and showing the price.
If it was hard to understand. If you select for example Line-X then 350 will be added to the "Summa" box, if you deselect it, it will be taken away from there. Default value should be 50 since one of the boxes is always selected.
function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above
return str;
}
function DisplayPrice(price){
var val1 = getRBtnName('part1').split(',');
var val2 = getRBtnName('part2').split(',');
var val3 = getRBtnName('part3').split(',');
var val4 = getRBtnName('part4').split(',');
var val5 = getRBtnName('part5').split(',');
var val6 = getRBtnName('part6').split(',');
var val7 = getRBtnName('part7').split(',');
var val8 = getRBtnName('part8').split(',');
var val9 = getRBtnName('part9').split(',');
You have a number of syntax errors in the script...
1. You cannot read the checkbox status with the radio button function "getRBtn()"
2. CSS comments are not // they are /* [comment] */ only
Look at changes made here...
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table class="puuks" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="puuks">
<td class="puuks" valign="top" width="350"> <strong>Valitse oikea kamina:</strong><br>
<input name="part1" type="radio" onclick="DisplayPrice();" value="0" checked="CHECKED">
Uppokamina (27kw) - 0 €- vakio<br>
<input type="radio" value="249" name="part1" onclick="DisplayPrice();">Ulkokamina (27kw) - 249.00 €<br>
<input type="radio" value="279" name="part1" onclick="DisplayPrice();">Uppokamina (40kw) - 279.00 €<br>
<input type="radio" value="395" name="part1" onclick="DisplayPrice();">Ulkokamina (40kw) - 395.00 €<br>
</td>
<td class="puuks" valign="top" width="350"> <strong>Kylpytynnyrin lisävarusteet:</strong><br>
<input type="checkbox" value="350" id="part2" onclick="DisplayPrice();">Line – X (suosittelemme) - 350.00 €<br>
<input type="checkbox" value="49" id="part3" onclick="DisplayPrice();">Kansi mänty (suosittelemme) – 49.00 €<br>
<input type="checkbox" value="45" id="part4" onclick="DisplayPrice();">Suojapressu - 45.00 €<br>
<input type="checkbox" value="40" id="part5" onclick="DisplayPrice();">Poltettu mänty – 40.00 €<br>
<input type="checkbox" value="250" id="part6" onclick="DisplayPrice();">Lämpökäsitelty mänty - 250.00 €<br>
<input type="checkbox" value="50" id="part7" checked onclick="return false" readonly>Valmiiksi koottuna – 50.00 €<br>
<input type="checkbox" value="300" id="part8" onclick="DisplayPrice();">Porejärjestelma – 300.00 €<br>
<input type="checkbox" value="300" id="part9" onclick="DisplayPrice();">LED valot - 300.00 €<br>
</td>
<td class="puuks" float="right" valign="top">
<h2>Summa</h2><input type="text" id="totalSum" value="" size="25" readonly border="0">
<p>Etu- ja sukunimi</p>
<input name="name" type="text" value="" size="25">
<p>Sähköposti</p> <input name="email" type="text" size="25">
<p>Puhelin</p> <input name="email" type="text" size="25">
<p>Osoite</p> <input name="email" type="text" size="25">
<p>Lisätietoja</p><textarea name="message" rows="3" cols="21"></textarea><br />
<input type="submit" value="Tilaa kylpytynnyri">
</form>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// From: http://www.webdeveloper.com/forum/sh...d.php?t=235581
function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above
return str;
}
function DisplayPrice(){
var sum = 0;
sum += Number(getRBtnName('part1')); // .split(','); ??? NOTHING TO SPLIT IN VALUE OF PART1 ???
for (var i=2; i<10; i++) {
var el = document.getElementById('part'+i);
if (el.checked) { sum += Number(el.value); } // ??? PART2..PART9 are CHECKBOX not RADIO ???
}
document.getElementById('totalSum').value=sum.toFixed(2)+" €";
}
DisplayPrice();
</script>
</body>
</html>
I don't have enough words how to thank you, mate. Now all i gotta do is figure out how to send all that info to a certain email address. Showing what radio button was clicked and what checkboxes have been clicked + all the data from contant form as well.
I know it might be wrong post where to type it, but could anyone help me creating a mail.php. What should i write there in order to send the checked checkbox info and selected radio button info to email ?
I don't have enough words how to thank you, mate. Now all i gotta do is figure out how to send all that info to a certain email address. Showing what radio button was clicked and what checkboxes have been clicked + all the data from contant form as well.
Again, thank you so much JMRKER
You're most welcome.
Happy to help.
You should be able to have access to a program similar to "formmail.cgi" on your server.
Most have it or something like it. Check with your administrator.
Hey, is it possible to add some text to the value part without messing up the calculator ?
<input type="checkbox" value="45" id="part4" onclick="DisplayPrice();">Suojapressu - 45.00 €<br> To add something like suojapressu (because this form has to send the selected value as an email to certain email)
I'm sorry but I don't understand the question.
It is probably because I can't read the language, but that is my problem.
If you add something to the "DisplayPrice()" function, you will be adding it to ALL actions of the checkbox change.
Is that your real need or is it that you wish to submit the total to the email after ALL checkboxes have been selected?
If the latter is the real need, you would be better off creating a new function that could be executed
to send the information via a <form> tag assignment using the "onsubmit="return someFunctionToEmail()"
See <input> tag with type="submit" value="Submit" via a google search. This would create a 'submit' button.
Okay let me try to make it more understandable.
Currently if i send the email it posts the value="value" to the email. BUT is it possible to send
<input type="checkbox" value="350" id="part2" onclick="DisplayPrice();">Line – X (suosittelemme) - 350.00 &euro
( see the bold part ) as well ?
I tried to add the name to value as value="350, linex" but that only messed up the calculator and it displays NaN. But in the email it says correctly what it needs to display.
Im having hard time explaining it, really sorry about that.
If you have msn or smth you could add me there mindfr34k@hotmail.com i could explain better maybe
Okay let me try to make it more understandable.
Currently if i send the email it posts the value="value" to the email. BUT is it possible to send
<input type="checkbox" value="350" id="part2" onclick="DisplayPrice();">Line – X (suosittelemme) - 350.00 &euro
( see the bold part ) as well ?
I tried to add the name to value as value="350, linex" but that only messed up the calculator and it displays NaN. But in the email it says correctly what it needs to display.
Im having hard time explaining it, really sorry about that.
If you have msn or smth you could add me there mindfr34k@hotmail.com i could explain better maybe
You have not indicated how you plan on saving the extra information nor how you plan to send it to your server,
so I'll leave that up to you using the information created in the "DisplayPrice()" function.
Note the other changes I made to the radiobutton and checkbox value settings.
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table class="puuks" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="puuks">
<td class="puuks" valign="top" width="350"> <strong>Valitse oikea kamina:</strong><br>
<input name="part1" type="radio" onclick="DisplayPrice();" value="0,uppokamina27" checked="CHECKED">
Uppokamina (27kw) - 0 €- vakio<br>
<input type="radio" value="249,ulkokamina" name="part1" onclick="DisplayPrice();">Ulkokamina (27kw) - 249.00 €<br>
<input type="radio" value="279,uppokamina40" name="part1" onclick="DisplayPrice();">Uppokamina (40kw) - 279.00 €<br>
<input type="radio" value="395,ulkokamina" name="part1" onclick="DisplayPrice();">Ulkokamina (40kw) - 395.00 €<br>
</td>
<td class="puuks" valign="top" width="350"> <strong>Kylpytynnyrin lisävarusteet:</strong><br>
<input type="checkbox" value="350,linex" id="part2" onclick="DisplayPrice();">Line – X (suosittelemme) - 350.00 €<br>
<input type="checkbox" value="49,kansi" id="part3" onclick="DisplayPrice();">Kansi mänty (suosittelemme) – 49.00 €<br>
<input type="checkbox" value="45,suojapressu" id="part4" onclick="DisplayPrice();">Suojapressu - 45.00 €<br>
<input type="checkbox" value="40,poltettu" id="part5" onclick="DisplayPrice();">Poltettu mänty – 40.00 €<br>
<input type="checkbox" value="250,manty" id="part6" onclick="DisplayPrice();">Lämpökäsitelty mänty - 250.00 €<br>
<input type="checkbox" value="50,valmiiksi" id="part7" checked onclick="return false" readonly>Valmiiksi koottuna – 50.00 €<br>
<input type="checkbox" value="300,porejarjestelma" id="part8" onclick="DisplayPrice();">Porejärjestelma – 300.00 €<br>
<input type="checkbox" value="300,led" id="part9" onclick="DisplayPrice();">LED valot - 300.00 €<br>
</td>
<td class="puuks" float="right" valign="top">
<h2>Summa</h2><input type="text" id="totalSum" value="" size="25" readonly border="0">
<p>Etu- ja sukunimi</p>
<input name="name" type="text" value="" size="25">
<p>Sähköposti</p> <input name="email" type="text" size="25">
<p>Puhelin</p> <input name="email" type="text" size="25">
<p>Osoite</p> <input name="email" type="text" size="25">
<p>Lisätietoja</p><textarea name="message" rows="3" cols="21"></textarea><br />
<input type="submit" value="Tilaa kylpytynnyri">
</form>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// From: http://www.webdeveloper.com/forum/sh...d.php?t=235581
function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above
return str;
}
function DisplayPrice(){
var sum = 0;
var tarr = getRBtnName('part1').split(',');
sum += Number(tarr[0]); // .split(',');
var emailInfo = tarr[1];
for (var i=2; i<10; i++) {
var el = document.getElementById('part'+i);
if (el.checked) {
tarr = el.value.split(',');
sum += Number(tarr[0]);
emailInfo += ','+tarr[1]; // saved for email purposes
}
}
document.getElementById('totalSum').value=sum.toFixed(2)+" €";
alert(emailInfo);
}
DisplayPrice();
</script>
</body>
</html>
Thanks, it works abit, but not fully. When sending the form it says error on line 10 (on contact.php)
foreach($_POST['cbox'] as $value) {
$check_boxes .= $value." ";
}
Those lines. But it still sends the email. In the email the radio button values are correct but the checkbox field has lost its numeric value now, it just leaves empty line now.
Bookmarks