WebDeveloper.com

WebDeveloper.com (http://www.webdeveloper.com/forum/index.php)
-   JavaScript (http://www.webdeveloper.com/forum/forumdisplay.php?f=3)
-   -   using the selected value of a pull down menu (http://www.webdeveloper.com/forum/showthread.php?t=36405)

heavenly_blue 06-02-2004 01:23 PM

using the selected value of a pull down menus (please help)
 
see my newer posts below...

theBody44 06-02-2004 04:11 PM

Your IF statements should look something like...
Code:

if (f.region.options[f.region.selectedIndex].value == "CA"){
...
}
else{
...
}

I'm not sure what you're logic is for the meat of the control statements??:confused: What is f?? I assumed it was your form containing the drop downs region and length. About that, length is an associated property to arrays and objects, so you might get an error by trying to name an element "length." Hope this gets you going in the right direction.

silent11 06-02-2004 04:24 PM

are you calculating prices on the client? If so, you're asking for trouble.

heavenly_blue 06-02-2004 05:02 PM

^^^^^^^
No this is just to display the total to the customer as they select different choices. The actual total will be determined server-side. I need this to work because the prices vary on the choices the user selects.

heavenly_blue 06-02-2004 05:04 PM

see updated posts...

heavenly_blue 06-02-2004 05:07 PM

see updated posts...

heavenly_blue 06-02-2004 05:13 PM

see updated posts...

heavenly_blue 06-02-2004 05:39 PM

see updated posts...

96turnerri 06-02-2004 05:49 PM

i have briefly looked at your code try this

if (f.region.options[f.region.selectedIndex].value == 1 && f.sublength.options[f.sublength.selectedIndex].value == 1){
var foo = 23;
}

and change

f.pay.value = windustrial + wcommercial + wtracts + wcustom + wmulti + wca03price + wca06price + wca12price + wns03price + wns06price + wns12price;

to

f.pay.value = foo + windustrial + wcommercial + wtracts + wcustom + wmulti + wca03price + wca06price + wca12price + wns03price + wns06price + wns12price;

i think thats what you are trying to do

heavenly_blue 06-02-2004 06:06 PM

Updated code...
 
Here's the new HTML

Code:

<html>
<head>
<script type="text/javascript" src="calculate.js">
</script>
</head>
<body>
<form method="post" action="#">
Please select your desired region
<br>
<br>

//1st select menu, "region"

<select name="region" onChange="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
<option selected value=0>Select one...</option>
<option value=1>California (entire state)</option>
<option value=2>Northern California</option>
<option value=3>Southern California</option>
</select>
<br>
<br>
Please select length of subscription
<br>
<br>

//2nd select menu, "sublength"

<select name="sublength" onChange="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
<option selected value=0>Select one...</option>
<option value=1>12 Months</option>
<option value=2>6 Months</option>
<option value=3>3 Months</option>
</select>
<br>
<br>
Please select your desired project types
<br>
$5.00 per month per project type
<br>
<br>
<table width="100%" border="0">
<tr>
<td>

//checkboxes

<input type="checkbox" name="commercial" onClick="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
Industrial
</td>
<td>
<input type="checkbox" name="industrial" onClick="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
Commercial
</td>
<td>
<input type="checkbox" name="tracts" onClick="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
Tracts
</td>
<td>
<input type="checkbox" name="custom" onClick="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
Custom homes
</td>
<td>
<input type="checkbox" name="multi" onClick="count(this.form);this.form.pay.value=formatCurrency(this.form.pay.value)">
Multi family homes
</td>
</tr>
</table>
<br>
Price per month

//textbox to display price

<input type="text" name="pay" readonly="1">
Total
<input type="text" name="total" readonly="1">
</form>
</body>
</html>

and heres the updated "calculate.js"
PHP Code:

//count function
function count(f){
//define variables
var windustrial, wcommercial, wtracts, wcustom, wmulti, wca03price, wca06price, wca12price, wns03price, wns06price, wns12price;
//if statement to set a value to a variable
if (f.region.options[f.region.selectedIndex].value == 1 && f.sublength.options[f.sublength.selectedIndex].value == 1){
wca12price=34.95
}else{
wca12price=0
}
//if statement to set a value to a variable
if (f.region.options[f.region.selectedIndex].value == 1 && f.sublength.options[f.sublength.selectedIndex].value == 2){
wca06price=44.95
}else{
wca06price=0
}
//if statement to set a value to a variable
if (f.region.options[f.region.selectedIndex].value == 1 && f.sublength.options[f.sublength.selectedIndex].value == 3){
wca03price=54.95
}else{
wca12price=0
}
//if statement to set a value to a variable
if (f.region.options[f.region.selectedIndex].value > 1 && f.sublength.options[f.sublength.selectedIndex].value == 1){
wns12price=19.95
}else{
wns12price=0
}
//if statement to set a value to a variable
if (f.region.options[f.region.selectedIndex].value > 1 && f.sublength.options[f.sublength.selectedIndex].value == 2){
wns06price=24.95
}else{
wns06price=0
}
//if statement to set a value to a variable
if (f.region.options[f.region.selectedIndex].value > 1 && f.sublength.options[f.sublength.selectedIndex].value == 3){
wns03price=29.95
}else{
wns03price=0
}
//check box variables
windustrial=(f.industrial.checked)?5:0;
wcommercial=(f.commercial.checked)?5:0;
wtracts=(f.tracts.checked)?5:0;
wcustom=(f.custom.checked)?5:0;
wmulti=(f.multi.checked)?5:0;
//add up all variables and store in "pay" variable
//problem might be here??
f.pay.value = windustrial + wcommercial + wtracts + wcustom + wmulti + wca03price + wca06price + wca12price + wns03price + wns06price + wns12price;
}
//function to convert "pay" into currency format
function formatCurrency(num) {
num = num.toString().replace(/$|,/g,'');
if(
isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(
cents<10)
cents = "0" + cents;
for (var
i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((
sign)?'':'-') + '$' + num + '.' + cents);
}

edit for comments in code

heavenly_blue 06-02-2004 06:08 PM

Each form object now affects the price when you check a box or select something from a menu...but no matter what you select, the price always says $0.00

I guess something isn't adding up right...I'm not sure how to fix it.

96turnerri 06-02-2004 06:09 PM

ok thanks for posting your code, whats wrong with it now, you forgot to mention that :)

heavenly_blue 06-02-2004 06:15 PM

everything works except for price doesn't add up correctly.

it always displays $0.00

heavenly_blue 06-02-2004 06:25 PM

Ok thanks for the help everyone...I have everything pretty much under control now. I think I can fix everything else by myself now.


All times are GMT -5. The time now is 12:11 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.