0

if i have this input on html code

<input value="0001" name="call" id="call">

how i call that value in php script without submit? like event onBlur or anything ??

the php file have query something like this :

select * from table where field = (input  html value)
user3502930
  • 153
  • 1
  • 2
  • 11
  • hmmm, so php runs on the server, onBlur, onChange runs on the client with javascript. This means you have to submit something to get the value back on the server. You could try using ajax – caramba Apr 25 '14 at 14:13
  • If you don't want to use a classic html form+submit, you need to use ajax request to comunicate with your server – Gwenc37 Apr 25 '14 at 14:23
  • how about seesion @cramba ?? is there any way to get the value input into php session function () { var x = document.getElementById("theid").defaultValue; } and the php $_SESSION['call']= var x; how to get that var x in session php ? is that possible ? – user3502930 Apr 25 '14 at 14:39

2 Answers2

0

you need to use Ajax for that.

<script>
$(document).ready(function()
{
var value = $("#call").val();
$.ajax({
url: "you file path where your php code is written to fetch value from database",
type:"POST",
data:{"call":value},
success:function(result){alert(result);}
})

});
</script>

and on php file.

<?php 
write code for sql connection ;

$feild_value = $_POST["call"];

// you can use this  $feild_value variable in query; 
select * from table where field = $feild_value ;

//echo query result here
echo $query_result;
die;
?>
Gwenc37
  • 2,064
  • 7
  • 18
  • 22
0

If you want to send this value to your PHP script when event Blur is triggered, then try this

<input value="0001" name="call" id="call">
<script type="text/javascript">
    $('#call').on('blur',function(){
        var value = $(this).val();
        $.ajax({
            url: "http://website.com/index.php",
            type: "POST",
            data: {"call": value},
            success: function(data){
                console.log(data);
            }
        });
    });
</script>

To set input value to PHP session you will need to run ajax request anyway, see this question Set Session variable using javascript in PHP

Community
  • 1
  • 1
alex23
  • 353
  • 2
  • 13
  • one more question the var send to php file...right? if i call a php file, var sent to the php file will be lost? – user3502930 Apr 25 '14 at 15:33
  • In my example on Blur event JS sends your '0001' value to php file `index.php`. In `index.php` you can use this '0001' value with the following code: `run_query($_POST['call']);` – alex23 Apr 25 '14 at 16:05