I have created the following code for a product select/payment form (don't know if there is a better
way) and I have been trying to make the following changes (unsuccessfully so far):
1) Eliminate the submit button and submit the form with onchange.
2) Open the action php page in a new window.
I am using this code for different payment options (i.e., cc processing and paypal). As such, there
are multiple forms on the page. The coding must be done in XHTML-Strict so I cannot use the name or
target attributes with FORM.
---------------
// Script
var Prices = new Array();
Prices[00] = "10.00";
Prices[01] = "12.50";
Prices[02] = "15.00";
Prices[03] = "20.00";
Prices[04] = "40.00";
Prices[05] = "60.00";
Prices[06] = "15.00";
Prices[07] = "20.00";
Prices[08] = "30.00";
Prices[09] = "45.00";
Prices[10] = "90.00";
Prices[11] = "150.00";
var Descriptions = new Array();
Descriptions[00] = '0.5 liter UNGLAZED Ceramic Bowl';
Descriptions[01] = '0.75 liter UNGLAZED Ceramic Bowl';
Descriptions[02] = '1.0 liter UNGLAZED Ceramic Bowl';
Descriptions[03] = '1.5 liter UNGLAZED Ceramic Bowl';
Descriptions[04] = '3.0 liter UNGLAZED Ceramic Bowl';
Descriptions[05] = '5.0 liter UNGLAZED Ceramic Bowl';
Descriptions[06] = '0.5 liter GLAZED Ceramic Bowl';
Descriptions[07] = '0.75 liter GLAZED Ceramic Bowl';
Descriptions[08] = '1.0 liter GLAZED Ceramic Bowl';
Descriptions[09] = '1.5 liter GLAZED Ceramic Bowl';
Descriptions[10] = '3.0 liter GLAZED Ceramic Bowl';
Descriptions[11] = '5.0 liter GLAZED Ceramic Bowl';
function updateXYform()
{
var i;
i = document.forms[0].xyselectamtanddesc.selectedIndex;
if(i > 0) {i = (i - 1);}
document.forms[0].amount.value = Prices[i];
document.forms[0].product_name.value = Descriptions[i];
}
//XHTML
<form id="xyform" action="http://www.myurl/order.php" method="post">
<input type="hidden" name="email" value="bl**@whereever.com" />
<input type="hidden" name="description" value="Red" />
<input type="hidden" name="amount" value="" />
<input type="hidden" name="product" value="" />
<select name="xyselectamtanddesc" onchange="updateXYform();">
<option selected="selected">Select Here...</option>
<optgroup label="Ceramic (unglazed)">
<option>0.5 L-$10.00</option>
<option>0.75 L-$12.50</option>
<option>1.0 L-$15.00</option>
<option>1.5 L-$20.00</option>
<option>3.0 L-$40.00</option>
<option>5.0 L-$60.00</option>
</optgroup>
<optgroup label="Ceramic (glazed)">
<option>0.5 L-$15.00</option>
<option>0.75 L-$20.00</option>
<option>1.0 L-$30.00</option>
<option>1.5 L-$45.00</option>
<option>3.0 L-$90.00</option>
<option>5.0 L-$150.00</option>
</optgroup>
</select>
<input type="submit" value="Buy Now" />
</form>
I tried adding the following command to the function statement
if(document.forms[0].xyselectamtanddesc.selectedIndex > 0)
{
window.open('http://www.myURL/order.php','newWindow');
}
and deleting the <input type="submit"...> command. The new window opens but no form data is POSTed.
Any suggestions and help is appreciated....Tom