It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Online Order Form?

Online Order Form?

Postby hanscellc on Mon Oct 03, 2011 3:56 pm

I have been playing with two options but just dont seem to get the coding right. Can someone please assist. Using ie9 but same problem with all browsers. Gives NaN.

first snippets.
HTML:

Code: Select all
<!-- Row 3, Col 3 purchase boxes -->
<td colspan="1" height="120" align="left">
<input style="margin-left: 60px" type="text" name="bed_359" size="3" maxlength="3" onchange="calculateValue(this.form)" /> R359</td></tr>

<!-- Row 10, Col 2 Order Value Box-->
<td colspan="1" align="left"><input style="margin-left: 60px" type="text" name="total" size="10"
onfocus="this.form.elements[0].focus()" />
</td></tr>


javaScript:

Code: Select all
// Function to calculate order value
function calculateValue(orders) {
var orderValue = 0;
var value = 0;
var itemPrice = 0;
var itemQuantity = 0;

// Run through all the product fields
for(var i = 0; i < orders.elements.length; ++i) {

// Get the current field
formField = orders.elements[i];

// Get the fields name
formName = formField.name;

// Items price extracted from name
itemPrice = parseFloat(formName.substring(formName.lastIndexOf("_") + 1));

// Get the Quantity
itemQuantity = parseInt(formField.value);

// Update the OrderValue
if(itemQuantity >= 0) {
value = itemQuantity * itemPrice;
orderValue += value;
}
}

// Display the total
orders.total.value = orderValue;
}


Second code:

Code: Select all
<!-- Row 9, Col 3 purchase boxes -->
<td colspan="1" height="120" align="left">
<select style="margin-left: 60px" name="shirt" value="215" onchange="calculateValue(this.form)" />
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></select> R215</td></tr>


Java

Code: Select all
// Function to calculate order value   
function calculateValue(orders) {
    var orderValue = 0;
    var value = 0;
    var itemPrice = 0;
    var itemQuantity = 0;

    // Run through all the product fields
    for(var i = 0; i < orders.elements.length; ++i) {

    // Get the current field
    formField = orders.elements[i];

    // Get the fields name
    formValue = formField;

    // Items price extracted from name
    itemPrice = formField;

    // Get the Quantity
    itemQuantity = formField.selectedIndex;

    // Update the OrderValue
    if(itemQuantity > 0) {
    orderValue += itemQuantity * itemPrice
    }
    }

    // Display the total
    orders.total.value = orderValue.toLocaleString();
}

Please help its probably something simple.
hanscellc
 
Posts: 1
Joined: Mon Oct 03, 2011 3:51 pm

Who is online

Users browsing this forum: No registered users and 1 guest