Member Avatar for rajarajan2017

Anything will possible if we have a solution. I expecting the solution for passing values.

how I can get value using JavaScript/AJAX or J Query from MySQL DB before submit on blur?????

Great Job Urtrivedi! This is good to know :)

how

any one

So please guide me in this regard

Go through the follwing code carefully. I have not used ajax here. Its simple php/javascript. I am assuming that your code-mf table is very small so i am storing its values in a javascript array and using it for calculation. make necessary changes whereever applicable.

<script lang='javascript'>
arrmfrates = new Array();
<?php 
	/*here find code, mf from database and create one javascript array*/
	
	/* following loop will create javacript asscoicate array as following
	arrmfrates["c8620"] = 2;
	arrmfrates["c8621"] = 1;
	arrmfrates["c8645"] = 5;
	*/
    
    $result=mysql_query("select code,mf from mytable");
	while ($row=$mysql_fetch_array($result ))
	{
		
		echo "\n arrmfrates['c".$row['code']."] = ".$row['code'].";";

	}
?>

/*this function will be called when user enters code, to find mf value stored in javascript array, this mf value is copied to "a" field of database*/
function findmf(code)
{

	if(arrmfrates['c'+code]!=undefined)
		document.getElementById("a").value=arrmfrates['c'+code];
	else
		document.getElementById("a").value="";
}

function calculate()
{
 //e is previous
 //f is current
 //g is new is f-e
 //code is code
 //a is mf
 
 	previous=parseFloat(document.getElementById("e").value);
 	curr=parseFloat(document.getElementById("f").value);

	if(!isNaN(previous) && !isNaN(curr) )
	{
	 	if(curr>=previous)
			document.getElementById("g").value=curr-previous*(parseFloat(document.getElementById("a").value));
		else
			document.getElementById("g").value="";
	}
	else
	{
		document.getElementById("g").value="";
	}
}
</script>


<body>
<form>
code <input type="text" name="code" id="code" value=""  class="input"    onblur='javascript:findmf(this.value);' > <br>
a <input type="text" name="a" id="a" value=""  class="input"   readonly> <br>

e <input type="text" name="e" id="e" value="340"  class="input" onblur='javascript:calculate();' > <br>
f <input type="text" name="f" id="f" value=""  class="input"  onblur='javascript:calculate();' > <br>
g <input type="text" name="g" id="g" value=""  class="input"  readonly >
</form>

Seems to me that you want the values calculated on the fly. You can do this on a simple Javascript, IMO this cannot be done by php without parsing the form values first.

Its solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.