View Single Post
Old 10-02-2012, 01:07 PM   PM User | #1
Cyberpops
New to the CF scene

 
Join Date: Oct 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Cyberpops is an unknown quantity at this point
combine results from sql query and javascript to calculate a field

I am very new to JavaScript, Have a problem regarding arrays within javascript. Straight to the point: I have HTML code:

Code:
<input type="text" name="conPrice" id="conPrice" size="16" maxlength="128"/>
<input type="text" name="OverP" id="OverP" size="16" maxlength="128"  />
<div id="slider"></div> //Slider
First field for quantity, that is pulled from slider. Second field for price from SQL table

SQL is based on a condition that there is four fields:

Code:
| ID | MIN | MAX | PRICE |
I am trying to get a price column prices in field OverP depending on what my sliders value is. so, if for example I have number 6 on a slider and it is between 1-7 as MIN and MAX, so the price would be 10.

I have this SQL:

PHP Code:
<?php
$x 
mysql_query("SELECT p_max AS max FROM dsd_price");
$y mysql_query("SELECT p_min AS min FROM dsd_price");
$z mysql_query("SELECT p_price AS price FROM dsd_price");
while (
$x_array mysql_fetch_array($x)){$max[] = $x_array;}
while (
$y_array mysql_fetch_array($y)){$min[] = $y_array;}
while (
$z_array mysql_fetch_array($z)){$price[] = $z_array;}
?>
And finally my JS:

Code:
<script>
$(document).ready(function slider() {
$( "#slider" ).slider({
    value:1,
    min: 0,
    max: 201,
    step: 1,
    slide: function( event, ui ) {
//Its setting the slider value to the element with id "conPrice" 
$("#conPrice" ).val(ui.value);
    }
});
});

$(document).ready(function calcul() {
var frm = document.dsd_form;
var quant = frm.conPrice;
var overp = ['<?php echo implode("','", $price); ?>'];
var mini = ['<?php echo implode("','", $min); ?>'];
var maxi = ['<?php echo implode("','", $max); ?>'];
for(index = 0; quant > mini[index], quant < maxi[index]; index++){
    $( "#OverP" ).val( overp[index] );
})
}   
</script>
I am not getting a result I wish, I know that the problem is with my JS. Hope for some suggestions to my topic as soon as possible.
Cyberpops is offline   Reply With Quote