jfur7
jfur7

Reputation: 77

jQuery - How to return value from php file and set it as a value to a textbox?

Let me start by saying I am new to using jQuery so this may seem like a dumb question. When the vin textbox focuses out it trigers the jQuery script to run.

$("#vin").focusout(function() {
    $("#stocknum").load("../jquery/update_stocknum.php?vin=" + $("#vin").val());
});

The PHP file is as follows and appears to be running correctly:

if(isset($_GET['vin'])){
$vin = $_GET['vin'];
if(strlen($vin) > 9) {
    $stocknum = substr($vin,-6);
    echo $stocknum;
}

What am i doing wrong so that I can set the value of the textbox to the what php is returning in the variable $stocknum?

Thanks in advance for your help!

Upvotes: 1

Views: 284

Answers (1)

Adil Shaikh
Adil Shaikh

Reputation: 44740

Try -

$("#vin").focusout(function() {
     $.get("../jquery/update_stocknum.php?vin=" + $("#vin").val(),function(data){
        $("#stocknum").val(data);
     });
});

Upvotes: 1

Related Questions