
October 7th, 2012, 01:43 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 12 m 29 sec
Reputation Power: 0
|
|
A problem getting data
Hi, I am quite new to JS
I have a problem retrieving a value to an input field.
So, I have HTML:
Code:
<input type="text" name="conPrice" id="conPrice" size="16" maxlength="128" onKeyUp='price()' />
<input type="text" name="OverP" id="OverP" size="16" readonly="readonly"/>
So, putting in a value in conPrice, I want a JavaScript to put a logic on sql statement:
PHP Code:
<?php
$x = mysql_query("SELECT p_max, p_price, p_min FROM dsd_price");
while ($x_array = mysql_fetch_array($x)){$max[] = $x_array['p_max']; $min[] = $x_array['p_min']; $price[] = $x_array['p_price'];}
?>
JS:
Code:
<script type="text/javascript">
function price() {
var frm=document.dsd_form;
var a=frm.conPrice;
var b=frm.OverP;
var max = <?php echo json_encode($max); ?>;
var min = <?php echo json_encode($min);?>;
var price = <?php echo json_encode($price);?>;
for (counter=(min.length / 2); counter<(min.length + 1); counter++){
if(a.value >= min[counter]){
if(a.value <= max[counter]){
b.value=min[counter]+ " " + max[counter] + " " + price[counter];
}
else{b.value = 0;}
}
}
}
</script>
The trouble is, that I am not getting correct array part call
|