TimmyTimbo
09-26-2005, 05:00 PM
Hi There,
Hope you can help.
I have a mini form, for which I am trying to calculate a price based on 3 variables. I thought it was correct, but I dont get a response.
Please let me know if you can help with this?
JAVASCRIPT:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getPriceForDays() {
if (weeks == 0, days == 1) return (price / 0.5);
if (weeks == 0, days == 2) return (price / 0.7);
if (weeks == 0, days == 1) return (price / 0.9);
if (weeks >= 1, days == 3) return (price / 0.2);
if (weeks >= 1, days == 2) return (price / 0.4);
if (weeks >= 1, days == 1) return (price / 0.2);
}
function getPriceForWeeks() {
if (weeks >= 0) return (price * weeks)
}
function getNumberOfWeeks() {
var weeks = document.calculator.weeks.value;
return (weeks == "") ? 0 : weeks;
}
function getNumberOfDays() {
var days = document.calculator.days.value;
return (days == "") ? 0 : days;
}
function getPrice() {
var price = document.calculator.price.value;
return (price == "") ? 0 : price;
}
function showResult(result) {
document.calculator.response.value = result;
}
fuction formatPrice(value) {
var result = (days * weeks);
return result;
// End -->
</Script>
FORM:
<form id="form1" name="calculator">
<table width="44%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Days</td>
<td width="78%"><label>
<input name="days" type="text" id="days" />
</label></td>
</tr>
<tr>
<td>Weeks</td>
<td><input type="text" name="weeks" /></td>
</tr>
<tr>
<td> </td>
<td><p>
<input type="hidden" name="price" value="100"/>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" onClick="formatPrice(value)"/>
</label>
</p></td>
</tr>
<tr>
<td>Total Price </td>
<td><label>
<input type="text" name="response" />
</label></td>
</tr>
</table>
<p> </p>
</form>
</body>
Basically, the code is for a rental, based on a number of days and weeks. The price is a hidden field. The problem i have is that the cost per day changes once the value of weeks is greater that 0.
I am new to this but have a good knowledge of HTML, and a growing knowldge of PHP, and Perl.
Cheers
Tim
Hope you can help.
I have a mini form, for which I am trying to calculate a price based on 3 variables. I thought it was correct, but I dont get a response.
Please let me know if you can help with this?
JAVASCRIPT:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getPriceForDays() {
if (weeks == 0, days == 1) return (price / 0.5);
if (weeks == 0, days == 2) return (price / 0.7);
if (weeks == 0, days == 1) return (price / 0.9);
if (weeks >= 1, days == 3) return (price / 0.2);
if (weeks >= 1, days == 2) return (price / 0.4);
if (weeks >= 1, days == 1) return (price / 0.2);
}
function getPriceForWeeks() {
if (weeks >= 0) return (price * weeks)
}
function getNumberOfWeeks() {
var weeks = document.calculator.weeks.value;
return (weeks == "") ? 0 : weeks;
}
function getNumberOfDays() {
var days = document.calculator.days.value;
return (days == "") ? 0 : days;
}
function getPrice() {
var price = document.calculator.price.value;
return (price == "") ? 0 : price;
}
function showResult(result) {
document.calculator.response.value = result;
}
fuction formatPrice(value) {
var result = (days * weeks);
return result;
// End -->
</Script>
FORM:
<form id="form1" name="calculator">
<table width="44%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%">Days</td>
<td width="78%"><label>
<input name="days" type="text" id="days" />
</label></td>
</tr>
<tr>
<td>Weeks</td>
<td><input type="text" name="weeks" /></td>
</tr>
<tr>
<td> </td>
<td><p>
<input type="hidden" name="price" value="100"/>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" onClick="formatPrice(value)"/>
</label>
</p></td>
</tr>
<tr>
<td>Total Price </td>
<td><label>
<input type="text" name="response" />
</label></td>
</tr>
</table>
<p> </p>
</form>
</body>
Basically, the code is for a rental, based on a number of days and weeks. The price is a hidden field. The problem i have is that the cost per day changes once the value of weeks is greater that 0.
I am new to this but have a good knowledge of HTML, and a growing knowldge of PHP, and Perl.
Cheers
Tim