I have an issue that I can't solve (I don't know how cause I'm a newbie in php and js). I have a text field and I want on blur trigger a function in js. My problem is that I want to pass a parameter in tnis function, which will get from a query. My test code is :
<script type="text/javascript">
function calcNums(nums){
var inText = "00.00";
if (document.expences.mytext.value != inText){
var mp = parseInt(nums.substr(0,2));
var lp = parseInt(nums.substr(3,2));
document.expences.mytext2.value = lpdeh*parseInt(document.expences.mytext.value)/100;
document.expences.mytext.value = mpdeh*parseInt(document.expences.mytext.value)/100;
}
}
</script>
<?php
$selNums = "SELECT DEH_NUMS FROM BUILDING WHERE idBUILDING = '3'";
$nums = mysql_query($selNums) or die("Could not execute query.");
<input type="text" name="mytext" id="mytext" value="00.00" onblur="calcNums($nums)"/>
<input type="text" name="mytext2" id="mytext2" value="00.00"/>
?>
My point is : I get $nums that is of type '50-50' (represents percentages). Get the initial value of "mytext" and calculate new values for "mytext" and "mytext2". example : $nums='60-40' initialMytext=100 --> new mytext=60 mytext2=40
If I put an inner var in calcNums() calculations are correct, but with the parameter is not triggered.
Can someone help? Thanks in advance!