Hello to all and thanks for your help in advance.
I am having been fighting with this problem for a couple of days now and after much unsuccessful research, I am still looking for an answer. So here it is. I have 9 hidden fields(qty12,24,36,72,144,288,576,1008,2016) on a form containing recordsets pulled from a mySQL database. The values from the database are there... (now we get to the problem.) I have a text box called quantity where a user inputs how many of a particular product they desire. if the user enters a number less than or equal to 12 it has to be multiplied by qty12 if its 13-24 it must use recordset qty24, if its between 25-36 it must use qty36 and so on all the way out to 2016. This is what I have written so far any help would be greatly appreciated. -
function getCalc(){
-
var f = document.prodform.quantity.value;
-
var g = document.prodform.qty12.value;
-
var h = document.prodform.qty24.value;
-
var j = document.prodform.qty36.value;
-
var k = document.prodform.qty72.value;
-
var l = document.prodform.qty144.value;
-
var m = document.prodform.qty288.value;
-
var n = document.prodform.qty576.value;
-
var o = document.prodform.qty1008.value;
-
var p = document.prodform.qty2016.value;
-
if(f >= 12){
-
Number(f * g);
-
}else if
-
(f < 24){
-
Number(f * h);
-
}else if
-
(f < 36){
-
Number(f * j);
-
}else if(f < 72){
-
Number(f * k);
-
}else if(f < 144){
-
Number(f * l);
-
}else if(f < 288){
-
Number(f * m);
-
}else if(f < 576){
-
Number(f * n);
-
}else if(f < 1008){
-
Number(f * o);
-
}else if(f < 2016){
-
Number(f * p);
-
}
-
-
}
-
-
alert (document.prodform.price.value);
The alert is only there so that I could make sure that everything worked. it will be removed and the value will be placed in a text box.
I am sure that there is a much easier way to do, any suggestions or places to go for research would be great! Again thank you all.
32 1460
You need to use parseInt to convert a string into an integer.
On line 12, it should be <=, not >=. Also, it's always a good idea to use meaningful variable names.
You could probably shorten the code using arrays, but in this case, it's just about manageable, so should be OK with the if-statements.
acoder thanks for the speedy reply. i am new javascript programming and i am not completely sure what you mean. the parseint functions converts which string? the user entered quantity? or the recordset? about the meaningful variables i get what you're saying. i will be changing those now.
You need to use parseInt to convert a string into an integer.
On line 12, it should be <=, not >=. Also, it's always a good idea to use meaningful variable names.
You could probably shorten the code using arrays, but in this case, it's just about manageable, so should be OK with the if-statements.
The user entered quantity, e.g. -
function getCalc(){
-
var quantity = parseInt(document.prodform.quantity.value);
-
//...
-
if (quantity <= 12) {
-
price = quantity * qty12;
-
} else if...
acoder this is what i did with what you sent me... unfortunately, it doesnt work in IE or FF (havent even bothered to check safari) any ideas????
thanks again for all the help. Maybe it's because the values from the recordsets have decimals?? also i need to be able to show these as currency values and not just integers... -
-
function getCalc(){
-
var qty = parseInt(document.prodform.quantity.value);
-
var qty12=document.prodform.qty12.value;
-
var qty24=document.prodform.qty24.value;
-
var qty36=document.prodform.qty36.value;
-
var qty72=document.prodform.qty72.value;
-
var qty144=document.prodform.qty144.value;
-
var qty288=document.prodform.qty288.value;
-
var qty576=document.prodform.qty576.value;
-
var qty1008=document.prodform.qty1008.value;
-
var qty2016=document.prodform.qty2016.value;
-
var price = document.prodform.price.value;
-
if(qty >= 12){
-
price = Number(qty * qty12);
-
}else if
-
(qty <= 24){
-
price = Number(qty * qty24);
-
}else if
-
(qty <= 36){
-
price = Number(qty * qty36);
-
}else if
-
(qty <= 72){
-
price = Number(qty * qty72);
-
}else if
-
(qty <= 144){
-
price = Number(qty * qty144);
-
}else if
-
(qty <= 288){
-
price = Number(qty * qty288);
-
}else if
-
(qty <= 576){
-
price = Number(qty * qty576);
-
}else if
-
(qty <= 1008){
-
price = Number(qty * qty1008);
-
}else if
-
(qty <= 2016){
-
price = qty * Number(qty2016); alert(document.prodform.price.value); }
-
-
}
The user entered quantity, e.g. -
function getCalc(){
-
var quantity = parseInt(document.prodform.quantity.value);
-
//...
-
if (quantity <= 12) {
-
price = quantity * qty12;
-
} else if...
If it's decimals, then you need to use parseFloat.
Since the hidden fields are being generated using server-side code, why not use similar code to generate the JavaScript variables, e.g. - var qty12 = <?php echo $val; ?>;
There's also no need to use Number syntax. The two variables will be numbers which you can multiply together.
OMG!!! this is getting really frustrating... here's the new code that also doesn't work. I understood what you meant about the parse float but since you said to use it on the user entered value, there's not a need for it as the user can only enter numbers that arent decimals..... IDK what is going on with this but i am really at a road block. any other ideas????? -
function getCalc(){
-
var qty = parseInt(document.prodform.quantity.value);
-
var qty12="<?php echo $row_Recordset1['qty12']; ?>";
-
var qty24="<?php echo $row_Recordset2['qty24']; ?>";
-
var qty36="<?php echo $row_Recordset3['qty36']; ?>";
-
var qty72="<?php echo $row_Recordset4['qty72']; ?>";
-
var qty144="<?php echo $row_Recordset5['qty144']; ?>";
-
var qty288="<?php echo $row_Recordset6['qty288']; ?>";
-
var qty576="<?php echo $row_Recordset7['qty576']; ?>";
-
var qty1008="<?php echo $row_Recordset8['qty1008']; ?>";
-
var qty2016="<?php echo $row_Recordset9['qty2016']; ?>";
-
var price = document.prodform.price.value;
-
-
if(qty >= 12){
-
price = (qty * qty12);
-
-
}else if
-
(qty <= 24){
-
price = (qty * qty24);
-
}else if
-
(qty <= 36){
-
price = (qty * qty36);
-
}else if
-
(qty <= 72){
-
price = (qty * qty72);
-
}else if
-
(qty <= 144){
-
price = (qty * qty144);
-
}else if
-
(qty <= 288){
-
price = (qty * qty288);
-
}else if
-
(qty <= 576){
-
price = (qty * qty576);
-
}else if
-
(qty <= 1008){
-
price = (qty * qty1008);
-
}else if
-
(qty <= 2016){
-
price = (qty * qty2016);
-
alert(document.prodform.price.value); }
-
-
}
-
-
If it's decimals, then you need to use parseFloat.
Since the hidden fields are being generated using server-side code, why not use similar code to generate the JavaScript variables, e.g. - var qty12 = <?php echo $val; ?>;
There's also no need to use Number syntax. The two variables will be numbers which you can multiply together.
qty12, qty24, etc. should be floats, not strings, e.g. - var qty12=<?php echo $row_Recordset1['qty12']; ?>;
-
var qty24=<?php echo $row_Recordset2['qty24']; ?>;
-
// and so on...
-
Why have you got qty >= 12? That would always multiply by the qty12 value. Surely, you mean (qty <= 12)?
acoder, have a question for ya... since i have those php variables being passed to hidden text boxes on the form, (and they actually show up) is there a way i can reference them instead of trying to call the php variable into the Javascriptfunction? i dont very much about php (still tryin to learn while i am doing this....) so i am trying to find the most streamlined method of making the client side do most of the work...
qty12, qty24, etc. should be floats, not strings, e.g. - var qty12=<?php echo $row_Recordset1['qty12']; ?>;
-
var qty24=<?php echo $row_Recordset2['qty24']; ?>;
-
// and so on...
-
Why have you got qty >= 12? That would always multiply by the qty12 value. Surely, you mean (qty <= 12)?
ARGGHHHH!!!! this doesnt work either?!?!?!?!? what i am doing wrong here????? -
function getCalc(){
-
var qty = parseInt("document.prodform.quantity.value",10);
-
-
alert(document.prodform.price.value);
-
-
var qty12 = parseFloat(<?php echo $row_Recordset1['qty12']; ?>);
-
var qty24 = parseFloat(<?php echo $row_Recordset2['qty24']; ?>);
-
var qty36 = parseFloat(<?php echo $row_Recordset3['qty36']; ?>);
-
var qty72 = parseFloat(<?php echo $row_Recordset4['qty72']; ?>);
-
var qty144 = parseFloat(<?php echo $row_Recordset5['qty144']; ?>);
-
var qty288 = parseFloat(<?php echo $row_Recordset6['qty288']; ?>);
-
var qty576 = parseFloat(<?php echo $row_Recordset7['qty576']; ?>);
-
var qty1008 = parseFloat(<?php echo $row_Recordset8['qty1008']; ?>);
-
var qty2016 = parseFloat(<?php echo $row_Recordset9['qty2016']; ?>);
-
-
var price = document.prodform.price.value;
-
if(qty <= 12){
-
price = (qty * qty12);
-
}else if
-
(qty <= 24){
-
price = (qty * qty24);
-
}else if
-
(qty <= 36){
-
price = (qty * qty36);
-
}else if
-
(qty <= 72){
-
price = (qty * qty72);
-
}else if
-
(qty <= 144){
-
price = (qty * qty144);
-
}else if
-
(qty <= 288){
-
price = (qty * qty288);
-
}else if
-
(qty <= 576){
-
price = (qty * qty576);
-
}else if
-
(qty <= 1008){
-
price = (qty * qty1008);
-
}else if
-
(qty <= 2016){
-
price = (qty * qty2016); }
-
}
-
-
-
acoder, have a question for ya... since i have those php variables being passed to hidden text boxes on the form, (and they actually show up) is there a way i can reference them instead of trying to call the php variable into the Javascriptfunction?
Of course! As an example, - var qty12 = parseFloat(document.prodform.qty12.value);
ARGGHHHH!!!! this doesnt work either?!?!?!?!? what i am doing wrong here?????
How are you calling getCalc()? What result were you expecting and what are you getting?
ok heres the source for the entire page. basically all my other functions work with the exception of the one to calculate quantity * price.
the code is supposed to do this:
user --> enters a quantity of 150-->getCalc says number is greater than 144 use the next one up = qty288--> cust(150) * qty288 --> spits out answer in text box for price. once that value is placed in the text box i need you use to later help add up the grand total.
price + setupchrg = grand total
price = function getCalc()
setup = function getSetup() ( this works in IE & FF) I took this out as it is 4 divs with drops downs that are just way too long to fill in here.
grandtot = function getgrandTotal()(this works in IE & FF) - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<?php require_once('mySQlConn.php'); ?>
-
<?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_mySQlConn, $mySQlConn);
-
-
$query_Recordset1 = "SELECT qty12 FROM price_breakdown WHERE productID = '4401'"; $Recordset1 = mysql_query($query_Recordset1, $mySQlConn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); mysql_select_db($database_mySQlConn, $mySQlConn);
-
-
$query_Recordset2 = "SELECT qty24 FROM price_breakdown WHERE productID='4401'"; $Recordset2 = mysql_query($query_Recordset2, $mySQlConn) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); mysql_select_db($database_mySQlConn, $mySQlConn);
-
-
$query_Recordset3 = "SELECT qty36 FROM price_breakdown WHERE productID='4401'"; $Recordset3 = mysql_query($query_Recordset3, $mySQlConn) or die(mysql_error()); $row_Recordset3 = mysql_fetch_assoc($Recordset3); $totalRows_Recordset3 = mysql_num_rows($Recordset3);
-
-
$query_Recordset4 = "SELECT qty72 FROM price_breakdown WHERE productID = '4401'"; $Recordset4 = mysql_query($query_Recordset4, $mySQlConn) or die(mysql_error()); $row_Recordset4 = mysql_fetch_assoc($Recordset4); $totalRows_Recordset4 = mysql_num_rows($Recordset4);
-
-
$query_Recordset5 = "SELECT qty144 FROM price_breakdown WHERE productID = '4401'"; $Recordset5 = mysql_query($query_Recordset5, $mySQlConn) or die(mysql_error()); $row_Recordset5 = mysql_fetch_assoc($Recordset5); $totalRows_Recordset5 = mysql_num_rows($Recordset5);
-
-
$query_Recordset6 = "SELECT qty288 FROM price_breakdown WHERE productID = '4401'"; $Recordset6 = mysql_query($query_Recordset6, $mySQlConn) or die(mysql_error()); $row_Recordset6 = mysql_fetch_assoc($Recordset6); $totalRows_Recordset6 = mysql_num_rows($Recordset6);
-
-
$query_Recordset7 = "SELECT qty576 FROM price_breakdown WHERE productID = '4401'"; $Recordset7 = mysql_query($query_Recordset7, $mySQlConn) or die(mysql_error()); $row_Recordset7 = mysql_fetch_assoc($Recordset7); $totalRows_Recordset7 = mysql_num_rows($Recordset7);
-
-
$query_Recordset8 = "SELECT qty1008 FROM price_breakdown WHERE productID = '4401'"; $Recordset8 = mysql_query($query_Recordset8, $mySQlConn) or die(mysql_error()); $row_Recordset8 = mysql_fetch_assoc($Recordset8); $totalRows_Recordset8 = mysql_num_rows($Recordset8);
-
-
$query_Recordset9 = "SELECT qty2016 FROM price_breakdown WHERE productID = '4401'"; $Recordset9 = mysql_query($query_Recordset9, $mySQlConn) or die(mysql_error()); $row_Recordset9 = mysql_fetch_assoc($Recordset9); $totalRows_Recordset9 = mysql_num_rows($Recordset9); ?>
-
-
-
<style type="text/css">
-
<!-- #apDiv1 { position:absolute; width:349px; height:225px; z-index:1; left: 456px; top: 86px; }
-
-
#apDiv2 { position:absolute; width:275px; height:229px; z-index:2; left: 12px; top: 80px; }
-
-
#apDiv3 { position:absolute; width:207px; height:236px; z-index:3; left: 16px; top: 81px; } -->
-
-
</style>
-
-
<style type="text/css">
-
<!-- #apDiv1 { position:absolute; width:200px; height:115px; z-index:1; left: 11px; top: 131px; visibility: hidden; }
-
-
#apDiv2 { position:absolute; width:200px; height:115px; z-index:1; left: 11px; top: 163px; visibility: hidden; }
-
-
#apDiv3 { position:absolute; width:200px; height:115px; z-index:1; left: 11px; top: 196px; visibility: hidden; }
-
-
#apDiv4 { position:absolute; width:200px; height:115px; z-index:1; left: 11px; top: 229px; visibility: hidden; }
-
-
#apDiv5 { position:absolute; width:302px; height:216px; z-index:2; left: 251px; top: 20px; }
-
-
#apDiv6 { position:absolute; width:316px; height:382px; z-index:3; left: 345px; top: 39px; } -->
-
-
</style>
-
-
<script language ="javascript" type="text/javascript">
-
-
function getCalc(){
-
var qty = parseInt(document.prodform.quantity.value);
-
var qty12 = parseFloat(<?php echo $row_Recordset1['qty12']; ?>);
-
var qty24 = parseFloat(<?php echo $row_Recordset2['qty24']; ?>);
-
var qty36 = parseFloat(<?php echo $row_Recordset3['qty36']; ?>);
-
var qty72 = parseFloat(<?php echo $row_Recordset4['qty72']; ?>);
-
var qty144 = parseFloat(<?php echo $row_Recordset5['qty144']; ?>);
-
var qty288 = parseFloat(<?php echo $row_Recordset6['qty288']; ?>);
-
var qty576 = parseFloat(<?php echo $row_Recordset7['qty576']; ?>);
-
var qty1008 = parseFloat(<?php echo $row_Recordset8['qty1008']; ?>);
-
var qty2016 = parseFloat(<?php echo $row_Recordset9['qty2016'];
-
?>);
-
var price = document.prodform.price.value;
-
if(qty <= 12){
-
price = (qty * qty12);
-
}else if{
-
(qty <= 24)
-
price = (qty * qty24);
-
}else if {
-
(qty <= 36)
-
price = (qty * qty36);
-
}else if {
-
(qty <= 72)
-
price = (qty * qty72);
-
}else if {
-
(qty <= 144)
-
price = (qty * qty144);
-
}else if {
-
(qty <= 288)
-
price = (qty * qty288);
-
}else if {
-
(qty <= 576)
-
price = (qty * qty576);
-
}else if {
-
(qty <= 1008)
-
price = (qty * qty1008);
-
}else if {
-
(qty <= 2016)
-
price = (qty*qty2016); } }
-
</script>
-
-
<script> function getSetup() {
-
var y = document.prodform.setupchrg.value;
-
y = (document.prodform.numsel.value * document.prodform.setup49.value); document.prodform.setupchrg.value = y;
-
}
-
-
function getgrandTotal() {
-
-
<!-- create var for prodform.price.value to be added here to complete price--> var x = document.prodform.price.value;
-
var y = document.prodform.setupchrg.value
-
var z = Number(x + y);
-
document.prodform.grandtotal.value = z;
-
}
-
</script>
-
-
<script language="javascript" type="text/javascript">
-
-
function dropnumb() {
-
var numsel = document.getElementById('numsel');
-
var maxind = Number(numsel.options[numsel.selectedIndex].value);
-
for(var x=1;x<=maxind;x++)
-
{
-
document.getElementById("apDiv"+x).style.visibility = "visible"; }
-
-
for(var x=x;x<=5;x++) { document.getElementById("apDiv"+x).style.visibility = "hidden";
-
}
-
}
-
</script>
-
-
</head>
-
<body>
-
<form action="#" method="get" name="prodform">
-
<input name="quantity" type="text" id="quantity" onfocus="getCalc()" /> <label>Qty.</label> <br /> <br /> <label>
-
-
<select name="position" id="position">
-
<option value="0">select</option>
-
<option value="1">Front Side Only</option>
-
<option value="2">Back Side Only</option>
-
<option value="3">Both Sides</option>
-
</select> Position</label>
-
<br /> <br />
-
-
<select id="numsel" name="numsel" onchange="dropnumb(0);">
-
<option value="0">Blank</option>
-
<option value="1">1</option>
-
<option value="2">2</option>
-
<option value="3">3</option>
-
<option value="4">4</option>
-
</select>
-
-
<br />
-
-
<input name="setup49" type="hidden" id="setup" value="49.00" />
-
<input name="qty12" type="hidden" id="qty12" value="<?php echo $row_Recordset1['qty12']; ?>" />
-
<br/>
-
<input name="qty24" type="hidden" id="qty24" value="<?php echo $row_Recordset2['qty24']; ?>"/>
-
<br />
-
<input name="qty36" type="hidden" id="qty36" value="<?php echo $row_Recordset3['qty36']; ?>"/>
-
<br />
-
<input name="qty72" type="hidden" id="qty72" value="<?php echo $row_Recordset4['qty72']; ?>"/>
-
<br />
-
<input name="qty144" type="hidden" id="qty144" value="<?php echo $row_Recordset5['qty144']; ?>"/>
-
<br />
-
<input name="qty288" type="hidden" id="qty288" value="<?php echo $row_Recordset6['qty288']; ?>"/>
-
<br />
-
<input name="qty576" type="hidden" id="qty576" value="<?php echo $row_Recordset7['qty576']; ?>"/>
-
<br />
-
<input name="qty1008" type="hidden" id="qty1008" value="<?php echo $row_Recordset8['qty1008']; ?>"/>
-
<br />
-
<input name="qty2016" type="hidden" id="qty2016" value="<?php echo $row_Recordset9['qty2016']; ?>"/>
-
<?php mysql_free_result($Recordset1);
-
mysql_free_result($Recordset2);
-
mysql_free_result($Recordset3);
-
mysql_free_result($Recordset4);
-
mysql_free_result($Recordset5);
-
mysql_free_result($Recordset6);
-
mysql_free_result($Recordset7);
-
mysql_free_result($Recordset8);
-
mysql_free_result($Recordset9); ?>
-
<div id="apDiv9">
-
<label> price</label> <input name="price" type="text" id="price" onfocus="getCalc()" />
-
<br />
-
<label> setup charge </label>
-
<input name="setupchrg" type="text" id="setupchrg" onfocus="getSetup()" /> <br />
-
<label>grand total
-
<input name="grandtotal" type="text" id="grandtotal" onfocus="getgrandTotal()" /> </label>
-
<br />
-
</div>
-
</form>
-
</body>
-
</html>
-
You've forgotten to set the value of the price field at the end of the function, i.e. - document.prodform.price.value = price;
you know? when i got home last night, i thought the same thing. when i got to work this morning, i had already placed it in the code. so idk.... but it still doesnt work either.
You've forgotten to set the value of the price field at the end of the function, i.e. - document.prodform.price.value = price;
For qty12 though to qty2016, use either: - var qty12 = <?php echo $row_Recordset1['qty12']; ?>;
or - var qty24 = parseFloat(document.prodform.qty24.value);
but not a combination of the two like you currently have.
acoder,
good news!!! i got it working but there is another problem. All the qty# fields are going to be less than 2016 (the last one in the list). so is there way i can say if qty is less than 24 BUT NO MORE than 35 use this formula?
or something similar thanks again -
-
if (qty <= 12 <24) <-- this {
-
y = qty * <?php echo $row_Recordset1['qty12']; ?>; document.prodform.price.value = y;
-
}
-
-
For qty12 though to qty2016, use either: - var qty12 = <?php echo $row_Recordset1['qty12']; ?>;
or - var qty24 = parseFloat(document.prodform.qty24.value);
but not a combination of the two like you currently have.
so is there way i can say if qty is less than 24 BUT NO MORE than 25 use this formula?
Have you got the numbers right here? If it's less than 24, it's never going to be more than 25.
see what i mean??? so that it doesnt interfere with the next recordset. - function getPrice(qty)
-
-
-
{
-
-
var qty = parseInt(document.prodform.quantity.value, 10);
-
-
-
var qty12 = <?php echo $row_Recordset1['qty12']; ?>;
-
var qty24 = <?php echo $row_Recordset2['qty24']; ?>;
-
var qty36 = <?php echo $row_Recordset3['qty36']; ?>;
-
var qty72 = <?php echo $row_Recordset4['qty72']; ?>;
-
var qty144 = <?php echo $row_Recordset5['qty144']; ?>;
-
var qty288 = <?php echo $row_Recordset6['qty288']; ?>;
-
var qty576 = <?php echo $row_Recordset7['qty576']; ?>;
-
var qty1008 = <?php echo $row_Recordset8['qty1008']; ?>;
-
var qty2016 = <?php echo $row_Recordset9['qty2016']; ?>;
-
-
var y = document.prodform.price.value;
-
-
if (qty >= 12 || qty>=23) ??this one i am not sure about...
-
{
-
y = qty * <?php echo $row_Recordset1['qty12']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 24 || qty >= 35); {
-
y = qty * <?php echo $row_Recordset2['qty24']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 36 || qty >= 71); {
-
y = qty * <?php echo $row_Recordset3['qty36']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 72 || qty >= 143); {
-
y = qty * <?php echo $row_Recordset4['qty72']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 144 || qty >= 287); {
-
y = qty * <?php echo $row_Recordset5['qty144']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 288 || qty >= 575); {
-
y = qty * <?php echo $row_Recordset6['qty288']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 576 || qty >= 1007); {
-
y = qty * <?php echo $row_Recordset7['qty576']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 1008 || qty >= 2015); {
-
y = qty * <?php echo $row_Recordset8['qty1008']; ?>;
-
document.prodform.price.value = y;
-
}
-
if(qty <= 2016); {
-
y = qty * <?php echo $row_Recordset9['qty2016']; ?>;
-
document.prodform.price.value = y;
-
}
-
}
Have you got the numbers right here? If it's less than 24, it's never going to be more than 25.
Oh, I see you've changed those else-if statements into separate if statements. Either use if-else-if or if you want them separate, use something like: - if (qty >= 12 && qty <=23)
this things still isnt right... i really dont know why!!!!!!
for some reason, when i enter a quantity, the only number it calculates by qty2016 value = 1.81. like it doesn't cycle thru the entire function, -
-
function getPrice() {
-
var qty = parseInt(document.prodform.quantity.value, 10);
-
var qty12 = <?php echo $row_Recordset1['qty12']; ?>;
-
var qty24 = <?php echo $row_Recordset2['qty24']; ?>;
-
var qty36 = <?php echo $row_Recordset3['qty36']; ?>;
-
var qty72 = <?php echo $row_Recordset4['qty72']; ?>;
-
var qty144 = <?php echo $row_Recordset5['qty144']; ?>;
-
var qty288 = <?php echo $row_Recordset6['qty288']; ?>;
-
var qty576 = <?php echo $row_Recordset7['qty576']; ?>;
-
var qty1008 = <?php echo $row_Recordset8['qty1008']; ?>;
-
var qty2016 = <?php echo $row_Recordset9['qty2016']; ?>;
-
var y = document.prodform.price.value;
-
-
if (qty >= 12 && qty <= 23) {
-
y = qty * <?php echo $row_Recordset1['qty12']; ?> document.prodform.price.value =y; }
-
-
else {
-
if(qty <= 24 && qty >= 35) {
-
y = qty * <?php echo $row_Recordset2['qty24']; ?>; document.prodform.price.value = y; }
-
else {
-
if(qty <= 36 && qty >= 71) {
-
y = qty * <?php echo $row_Recordset3['qty36']; ?>; document.prodform.price.value = y; }
-
else {
-
if(qty <= 72 && qty >= 143) {
-
y = qty * <?php echo $row_Recordset4['qty72']; ?>; document.prodform.price.value = y; }
-
else
-
{
-
if(qty <= 144 && qty >= 287) {
-
y = qty * <?php echo $row_Recordset5['qty144']; ?>; document.prodform.price.value = y; }
-
else
-
{
-
if(qty <= 288 && qty >= 575) {
-
y = qty * <?php echo $row_Recordset6['qty288']; ?>; document.prodform.price.value = y; }
-
else
-
{
-
if(qty <= 576 && qty >= 1007) {
-
y = qty * <?php echo $row_Recordset7['qty576']; ?>; document.prodform.price.value = y; }
-
else
-
{
-
if(qty <= 1008 && qty >= 2015) {
-
y = qty * <?php echo $row_Recordset8['qty1008']; ?>; document.prodform.price.value = y; }
-
else .
-
{
-
if(qty <= 2016) {
-
y = qty * <?php echo $row_Recordset9['qty2016']; ?>; document.prodform.price.value = y; } } };
-
}
-
-
You can't have multiple else statements, but you can have multiple else-if statements. So - if (cond) {
-
...
-
} else if (cond) {
-
...
-
} else if (cond) {
-
...
-
} else {
-
...
-
}
would be ok, but - if (cond) {
-
...
-
} else {
-
if (cond) {
-
...
-
}
-
} else {
-
if (cond) {
-
...
-
}
-
} else {
-
...
-
}
wouldn't be.
this thing still isnt right. instead of cycling thru the if else if statement it either chooses between qty12 or qty2016 and nothing in the middle and if i punch in a different number it still references it's original calculation.... here's the newest, please let me know. -
-
if (qty <= 12 && qty >= 23) { with this one the min they can order is 12
-
y = qty * 3.17;
-
document.prodform.price.value = y;
-
alert(y);
-
-
} else if (qty <= 24 && qty >= 35) {
-
y = qty * 2.95;
-
document.prodform.price.value = y;
-
alert(y);
-
-
} else if (qty <= 36 && qty >= 71) {
-
y = qty * 2.72;
-
document.prodform.price.value = y;
-
alert(y);
-
-
} else if (qty <= 72 && qty >= 143) {
-
y = qty * 2.27;
-
document.prodform.price.value = y;
-
alert(y);
-
-
} else if (qty <= 144 && qty >= 287) {
-
y = qty * 1.94;
-
document.prodform.price.value = y;
-
alert(y);
-
-
} else if (qty <= 288 && qty >= 575) {
-
y = qty * 1.92;
-
document.prodform.price.value = y;
-
alert(y);
-
-
} else if(qty <= 576 && qty >= 1007){
-
y = qty * 1.88;
-
document.prodform.price.value = y; alert(y);
-
-
} else if (qty <= 1008 && qty >= 2015) {
-
y = qty * 1.85;
-
document.prodform.price.value = y; alert(y);
-
-
} else if (qty <= 2016){
-
y = qty * 1.81;
-
document.prodform.price.value = y;
-
alert(y);
-
-
}
-
-
You can't have multiple else statements, but you can have multiple else-if statements. So -
if (cond) {
-
...
-
} else if (cond) {
-
...
-
} else if (cond) {
-
...
-
} else {
-
...
-
}
would be ok, but - if (cond) {
-
...
-
} else {
-
if (cond) {
-
...
-
}
-
} else {
-
if (cond) {
-
...
-
}
-
} else {
-
...
-
}
wouldn't be.
I think the logic has gone a bit awry. You need to swap the <= and >= around, so - if (qty <= 12 && qty >= 23) {
becomes - if (qty >= 12 && qty <= 23) {
but that doesnt explain why it only uses the qty2016 value.
the first one has to be if qty greater than or equal to12 and is also less than 23, calculate the quantity by 3.17 (php echo recordset1)
if quantity is greater than or equal to 24 and is also less than or equal to 35, calculate quantity by 2.95 (php echo recordset2)
and so on til it gets to 2016. also something else that has me confused is why it doesnt redo it if the quantity number is changed at anytime.
I think the logic has gone a bit awry. You need to swap the <= and >= around, so - if (qty <= 12 && qty >= 23) {
becomes - if (qty >= 12 && qty <= 23) {
The reason why it only gives the qty2016 value is because that's the only condition that can be met. Think about it. If you have qty <=12 and qty >=23, then the qty value has to be less than or equal to 12 AND greater than or equal to 23 which is impossible!
ok acoder, how about this?
could i do qty <= 12 && qty > 24?
that way the logic would be asking if this quantity is in between these two numbers? would that be possible???
No, see post #24. It should be qty >= 12 && qty < 24
IT WORKS! acoder, thanks for all your help you have no idea how much i really appreciate it.
thanks to bytes for having ppl on here like you that we can talk to inorder to get help.
this will be the last question for this thread. is there any way i can "fix" the decimals to two places? sometimes i ll get a value that looks like this: 1586.7199999999998 instead of making it 1586.72.
No, see post #24. It should be qty >= 12 && qty < 24
Glad to hear that it's working.
As for the last question, use the toFixed() method.
worked perfectly thank you again acoder
Sign in to post your reply or Sign up for a free account.
Similar topics
by: SABmore |
last post by:
Is there a performance advantage to parsing thru a recordset verus using an
array?
I'm currently trying to populate a listbox by returning data from my
database, then either parsing thru the...
|
by: Keith Chadwick |
last post by:
We current have a bunch of web services that make user of the SQLXML object.
A template is created in code which calls several stored procedures each of
which returns multiple xml recordsets from...
|
by: allyn44 |
last post by:
Hello,
I have built a serch form for users to edit records. I only want them
to pull up the record they need, and I want to check for nulls. There
should not be dupes becasue the underlying...
|
by: Thelma Lubkin |
last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar:
myVar = _
DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '")
I don't believe that this will work, and I...
|
by: cnoobie |
last post by:
Problem 1 - Min, Mean, Max
Write a program that reads in successive integer values from the user. The user will indicate termination of these values with the sentinel value 0 (zero). After the...
|
by: south622 |
last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
|
by: Isaac |
last post by:
I am still working on my database of work performance for the company
I work for. I have a form (frmtblOccurrences) based on a table
(tblOccurrences). I also have tblAgent that contains personal...
|
by: Sleepwalker817 |
last post by:
Hello, I am trying to create a program that is supposed to calculate and print the average of several grades entered by the user.
The output is supposed to look something like this:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |