Forum Moderators: open
<script language="JavaScript" type="text/javascript">
function calc2(){
var totalStr = ''; // for testing only
var totalValue=0;
var DDL;
var cnt = 0; // for testing only
for (var j=1; j<=2; j++) {
DDL = document.getElementById('dropDownList'+j);
temp = DDL.options[DDL.selectedIndex].value;
totalValue += Number(temp);
if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
}
document.forms[0].total.value=totalValue;
}
</script>
<form id="dropDownForm2" name="dropDownForm2">
<td class="style14"> <select id="dropDownList1" class="style10" name="D10" onchange="calc2();">
<option selected="" value="10">item1</option>
<option value="20">item2</option>
<option value="30">item3</option>
</select> <br />
</td>
<td class="style14"> <select id="dropDownList2" class="style10" name="D11" onchange="calc2();">
<option href="alloy.htm" selected="" value="11">item4</option>
<option value="12">item5</option>
<option value="13">item6</option>
</select><br />
total </td>
<input class="style10" name="total" onfocus="blur()" readonly="" size="4" style="width: 46px; height: 22px;" type="text" value="958" /></form>
<form action="http://www.romancart.com/cart.asp" method="post">
<input name="storeid" type="hidden" value="43579" />
<input name="itemcode" type="hidden" value="TF Series" />Frameset
<select name="itemname2">
<option value="TF100" value="TF100">item1</option>
<option value="TF300C" value="TF300">item2</option>
<option value="TF400C" value="TF400">item3</option>
</select><br />
Groupset <select name="itemname5">
<option value="SL T1" value1="SL T1">item4</option>
<option value="SLR T1" value1="SLR T1">item5</option>
</select><br />
<input type="submit" value="Add to basket" />
</form>
no idea how to go about getting 2 values from one dropdown though.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Split</title>
<script type="text/javascript">
function checkForm(form) {
var msg='';
ind = document.getElementById('dropDownList1').selectedIndex;
val = document.getElementById('dropDownList1').options[ind].value;
values = val.split(":");
if (! values[0]) { values[0]='None Selected'; }
if (! values[1]) { values[1]='0.00'; }
document.getElementById('my-selected').innerHTML=values[0]; // itemcode
document.getElementById('my-totals').innerHTML=values[1]; // cost?
if (form) {
if (document.getElementById('dropDownList1').selectedIndex==0) {
msg += 'Please select an item to add to cart.';
}
if (msg != '') { alert(msg); return false; }
else {
// uncomment for actual use
// return true;
// Remove for actual use
alert('Would submit OK here');
return false;
}
}
}
</script>
</head>
<body>
<form action="" onsubmit="return checkForm(this);">
<p><select id="dropDownList1" class="style10" name="D10" onchange="checkForm();">
<option value="">select</option>
<option value="TF100:10">item1</option>
<option value="TF200:20">item2</option>
<option value="TF100:30">item3</option>
</select>
</p>
<p><strong>Selected:</strong> <span id="my-selected">None Selected</span>
<strong>Total:</strong> $<span id="my-totals">0.00</span></p>
<p><input type="submit" value="Add Me"></p>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Split</title>
<script type="text/javascript">
function checkForm(form) {
var msg='';
ind = document.getElementById('dropDownList1').selectedIndex;
val = document.getElementById('dropDownList1').options[ind].value;
values = val.split(":");
if (! values[0]) { values[0]='None Selected'; }
if (! values[1]) { values[1]='0.00'; }
document.getElementById('my-selected').innerHTML=values[0]; // itemcode
document.getElementById('my-totals').innerHTML=values[1]; // cost?
if (form) {
if (document.getElementById('dropDownList1').selectedIndex==0) {
msg += 'Please select an item to add to cart.';
}
if (msg != '') { alert(msg); return false; }
else {
// uncomment for actual use
// return true;
// Remove for actual use
alert('Would submit OK here');
return false;
}
}
}
</script>
</head>
<body>
<form action="http://www.romancart.com/cart.asp" method="post" >
<input name="storeid" type="hidden" value="43579" />
<input name="itemcode" type="hidden" value="TF Series" />Frameset
<select id="dropDownList1" class="style10" name="itemname2" onchange="checkForm();">
<option value="">select</option>
<option value="TF100:10">item1</option>
<option value="TF200:20">item2</option>
<option value="TF100:30">item3</option>
</select>
<p><strong>Selected:</strong> <span id="my-selected">None Selected</span>
<strong>Total:</strong> $<span id="my-totals">0.00</span></p>
<p><input type="submit" value="Add to basket" /></p>
</form>
</body>
</html> I guess this is what you meant by combining calc2() and any functions for "add to cart".
if (form) {
if (document.getElementById('dropDownList1').selectedIndex==0) {
msg += 'Please select an item to add to cart.';
}
if (msg != '') { alert(msg); return false; }
else { return true; }
}
<%
if Request.Form("dropDownList1") Then
selectArray = Split(Request.Form("dropDownList1"), ":")
itemcode=selectArray(0)
price=selectArray(1)
End if
%>
if (form) {
if (document.getElementById('dropDownList1').selectedIndex==0) {
msg += 'Please select an item to add to cart.';
}
if (msg != '') { alert(msg); return false; }
else {
// Let's just use "dropdown1" as the selected code value by changing the value of the option . . .
document.getElementById('dropDownList1').options[ind].value=values[0];
// create a hidden field for the price
var newfield = document.createElement('div');
newdiv.innerHTML = '<input type="hidden" name="product-1-price" value="' . values[1] . '">';
// We already have a reference to the form in the variable "form"
// no need to use document.getElementById again (doesn't have an id anyway)
form.appendChild(newdiv);
return true;
}
}