PDA

View Full Version : Date and sum problems



p206ab
Jun 3rd, 2012, 01:41 PM
Hello, i'm writing a HTML form as a pricelist for services.
But now I want to add two things and I just can't figure them out.

I have this code:

<script type="text/javascript">
function count()
{
var a=document.getElementById("fotochosen").name;
var b=document.getElementById("videochosen").name;
var c=document.getElementById("leng").name;
result=a+b+c;
alert("Total price is :" + result + "$");
}

</script>
</head>
<body>

<form action="php/pricelist.php" method="post">



Choose desired services:: <br />

<input type="checkbox" name="foto" value="photo" /> Photography<br /> <input type="hidden" id="fotochosen" name="150" />

<input type="checkbox" name="video" value="video" /> Videorecording <br /><input type="hidden" id="videochosen " name="200" />
<br/>
Pick an event:
<br/>
<select name="event">
<option value="wedding">Wedding</option>
<option value="birthday">Birthday</option>

</select>
<br><br />
Select date:
<br>
<input type="date" name="date"><br>
<br>

Aproximate length (in hours)):
<br>
<input type="number" name="length"><br>
<input type="hidden" id="leng"
if (leng<3)
{
name="50";
}
else
{
name="100";
}
/>
<br>

</select>
<br><br />
<button type="button" onclick="count()">Count your price!</button>


1. What I want to achieve is that function count() would sum all selected hidden names values, which are prices. But it doesn't, it just writes all values down, like 10020015050.

2. In the date input, I've been searching for a code which would check today's date and selected one, and see if there is more than 10days between them. If yes it would cost 50, if not it would 100.

Any hints would be much appreciated.
Thanks in advance!

p206ab
Jun 3rd, 2012, 02:20 PM
iBall, thank you!
I changed that part of code and all names to value and now it works. :thumbsup:
Except it still counts all of them, non depended on what I select or what I don't.

EpicWebDesign
Jun 3rd, 2012, 05:11 PM
You need determine if a checkbox was selected and then assign a value of 0 to any that were NOT selected. For instance:


if (document.getElementById("foto").checked == true) {
var a=Number(document.getElementById("fotochosen");
}
else {
var a=0;
}

p206ab
Jun 3rd, 2012, 07:04 PM
You need determine if a checkbox was selected and then assign a value of 0 to any that were NOT selected. For instance:


if (document.getElementById("foto").checked == true) {
var a=Number(document.getElementById("fotochosen");
}
else {
var a=0;
}


Thank you very much!