I want to change the readonly value of an HTML textbox from the value I got in my jquery/ajax method after an admin , inputs the employee id number and presses enter. But I cant seem to get it to work. What am I doing wrong?
this is the HTML
<td class="text2"><div align="right" >User: </div></td>
<td class="style4" align="left">
<input type="text" name="wb_user" id="wb_name" size="18" maxlength="50" value="<?php echo $_POST["wb_user"];?>" class="form-control" placeholder="Input Employee ID and press ENTER" />
</span></td>
<td class="text2"><div align="right" class="style4">IP/Network Address: </div></td>
<td align="left" class="style4">
<input type="text" name="wb_ip" size="15" maxlength="25" class="form-control" />
</span></td>
</tr>
<tr>
<td class="text2"><div align="right" class="style4">Employee Name: </div></td>
<td class="style4" align="left">
<input type="text" name="wb_emname" id="wb_empname" size="20" maxlength="50" class="form-control" readonly />
</span></td>
This is the script.
$(document).ready(function() {
load_data();
function load_data(query){
$.ajax ({
url: "fetch.php",
method: "POST",
data: {query:query},
succes: function (result)
{
$('#wb_empname').html(result);
},
error: function() {
alert('There was some error performing the AJAX call!');
}
});
}
$("#wb_name").on('keyup',function(event) {
if (event.key === "Enter") {
// Do something
var search= $(this).val();
console.log(search);
if(search !=''){
load_data(search);
}
}
});
This is the fetch.php:
<?php
if(isset($_POST["query"])){
$q= $_POST["query"];
//$branchcodeID= $_POST['wb_branch'];
try {
$dbh = new PDO('mysql:host=localhost;dbname=myhris43_test', 'root', 'bvgtxpkrf7');
foreach($dbh->query("SELECT id_emp from tblemployee where id_emp=$q") as $row) {
$result= $row['id_emp'];
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
Please help me, Im new to jQuery and ajax.