/    Sign up×
Community /Pin to ProfileBookmark

Form Calculator with Dropdowns

Hi
I have a form with dropdown boxes for product Items and cities
My product dropdown will have the product name but somhowe I need the product name to be posted to me so I’m not sure what the value=”” must be.
If I put the amount then the form will only post that and if I put the name of the product then I can’t caculate so if someone has an idea I would appreciate the help.
The cities have the same dilemma.
So the Customer will choose his City and the the amount will change accordingly and same with the product dropdown.
At the end it must add up the two values the product cost and the courier cost to the city for the customer to see.
The text fields must not be editable.

Unfortunately I have nothing to go by Cause I’m still searching for code.
The problem is to find something specific
I’ll appreciate any help or guidance

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 29.2009 — Use a split value or an id for the calculation
<option value="product:12.34">product</option>
//or
<option value="product" id="$12.34">product</option>
Copy linkTweet thisAlerts:
@JPMauthorMar 29.2009 — Hi Fang

Thanks that is an Idea

Below basically what I want but the form does not calculate the fields when I change the dropdowns

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>


<script type="text/javascript">

////////////////////////////////////////////////////////////////////////////////////////

// Cities

////////////////////////////////////////////////////////////////////////////////////////

// Name,Line1,Line2,Line3,Line4,Line5,Dell,Tel,FAX,FaxEmail,Email,Webpage

var CityCourierCost = [

['Please select your City','',''],

['Cape Town','200','Cape Town'],

['JHB','600','JHB']

//['Witbank','amount']

];

function SetupCity(TA) {

var str = "<select id='City' onchange='CityInfo()'>";

for (var i=0; i<CityCourierCost.length; i++) {

str += '<option value="'+CityCourierCost[i].join('|')+'">'+CityCourierCost[i][0]+'</option>';

}

str +='</select>';

document.write(str);

}



function CityInfo() {

var sel = document.getElementById('City').selectedIndex;

var tmp = []; tmp.push(sel);

for (var i=1; i<3; i++) { tmp.push(CityCourierCost[sel][i]); }

document.getElementById('CourierCost').value = tmp[1];

document.getElementById('CityName').value = tmp[2];



}



////////////////////////////////////////////////////////////////////////////////////////

// Products

////////////////////////////////////////////////////////////////////////////////////////



var ProductItemCost = [

['Please select your Product','',''],

['Alpine','1200','Alpine'],

['Surento','800','Surento']

//['Witbank','amount']

];

function SetupProduct(TA) {

var str = "<select id='Product' onchange='ProductInfo()'>";

for (var i=0; i<ProductItemCost.length; i++) {

str += '<option value="'+ProductItemCost[i].join('|')+'">'+ProductItemCost[i][0]+'</option>';

}

str +='</select>';

document.write(str);

}



function ProductInfo() {

var sel = document.getElementById('Product').selectedIndex;

var tmp = []; tmp.push(sel);

for (var i=1; i<3; i++) { tmp.push(ProductItemCost[sel][i]); }

document.getElementById('ProductCost').value = tmp[1];

document.getElementById('ProductName').value = tmp[2];

}



////////////////////////////////////////////////////////////////////////////////////////

// Calculation

////////////////////////////////////////////////////////////////////////////////////////





function calc(A,B,SUM) {

var one = Number(A);

if (isNaN(one)) { alert('Invalid entry: '+A); one=0; }

var two = Number(document.getElementById(?.value);

if (isNaN(two)) { alert('Invalid entry: '+?; two=0; }

document.getElementById(SUM).value = one + two;

}





</script>





</head>



<body>

<form name="theform" action="http://www.hashemian.com/tools/form-grabber.php" method="post">

<table width="863" height="145">

<tr>

<td width="101" height="24">City</td>

<td width="207"><script type="text/javascript">SetupCity();</script></td>

<td width="51">Amount</td>

<td width="484"><input type="text" name="City" id="CourierCost" size="40" value="" onChange="calc(this.value,'CourierCost','result')"></td>

</tr>

<tr>

<td height="21">&nbsp;</td>

<td>&nbsp;</td>

<td>City:</td>

<td><input type="text" name="CityName" id="CityName" size="40" value="" ></td>

</tr>

<tr>

<td height="24">Product</td>

<td><script type="text/javascript">SetupProduct();</script></td>

<td>Amount</td>

<td><input type="text" name="ProductCost" id="ProductCost" size="40" value="" onChange="calc(this.value,'ProductCost','result')"></td>

</tr>

<tr>

<td height="24">&nbsp;</td>

<td>&nbsp;</td>

<td>Name</td>

<td><input type="text" name="ProductName" id="ProductName" size="40" value="" onChange="calc(this.value,'ProductCost','result')"></td>

</tr>

<tr>

<td height="24">&nbsp;</td>

<td><input name="sum" value="" id="result" readonly style="border:0px;"></td>

<td>&nbsp;</td>

<td><font size="2" face="Arial, Helvetica, sans-serif"><b>

<input type="submit" value="Submit" name="Submit" style="Background: #c3d9ff" />

<input type="hidden" name="__FG_SITE_IDENTIFIER__"

value="1TrycdQmp.Cm6O4lGCmb7ErXs91ubx1" />

<input type="hidden" name="__FG_THANKS_PAGE_RDR__"

value="http://www.glassfurniture.co.za/thankyou.html" />

</b></font></td>

</tr>

</table>

</form>

</body>

</html>



Any input will help

Thanks
×

Success!

Help @JPM spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...