gobayview
12-18-2003, 11:54 AM
I'm not a javascript brainiac (oh contraire), and am having some problems integrating a VERY simple code. This is in an osCommerce setup, and I want to add a button next to an input field that when clicked will calculate and insert an alternate price as a percent of the original price.
My problem comes from the fact that the second price field name contains square brackets, and this complicates the javascript code. I know this deals with a potential array of values associated with the field, but I am only using 1 value. I've looked into escaping the characters in the script, utilizing special characters for '[' and']', and treating the form field as an element referenced by index, all to no avail.
The imortant part of the code follows. Could someone PLEASE just tell me what to change to make this work. I've spent way to much time on this simple problem.
<html>
<head>
<script>
function CalcDiscount()
{
var RetailPrice = eval(document.new_product.products_price.value)
var Discount = .75
document.new_product.sppcprice[1]; = RetailPrice * Discount
}
</SCRIPT>
</head>
<body>
<form name="new_product">
<input type="text" name="products_price" size="4"><br><br>
<input type="text" name="sppcprice[1]" size="4">
<input type="button" value="Recalculate" onClick="CalcDiscount()">
</form>
</body>
</html>
Thanks in advance.
Spice
My problem comes from the fact that the second price field name contains square brackets, and this complicates the javascript code. I know this deals with a potential array of values associated with the field, but I am only using 1 value. I've looked into escaping the characters in the script, utilizing special characters for '[' and']', and treating the form field as an element referenced by index, all to no avail.
The imortant part of the code follows. Could someone PLEASE just tell me what to change to make this work. I've spent way to much time on this simple problem.
<html>
<head>
<script>
function CalcDiscount()
{
var RetailPrice = eval(document.new_product.products_price.value)
var Discount = .75
document.new_product.sppcprice[1]; = RetailPrice * Discount
}
</SCRIPT>
</head>
<body>
<form name="new_product">
<input type="text" name="products_price" size="4"><br><br>
<input type="text" name="sppcprice[1]" size="4">
<input type="button" value="Recalculate" onClick="CalcDiscount()">
</form>
</body>
</html>
Thanks in advance.
Spice