I am trying to get data from mysql
database in a textfield
of html page. I am using php
to take data from database and using json
to give data to javascript
. Then using id i am throwing value to textfield
. But it is not working. I am easily getting the phone number in div
or li
tag using id but the same value does not appear in the textfield
.
my javascript is like this
$('#tenantcontactTP').live('pageshow', function(event) {
var id = '[email protected]';
$.getJSON('tenantcontact.php?id='+id, displayEmployee);
});
function displayEmployee(data) {
var employee = data.item;
if (employee.TenantPhoneNumber) {
$('#tphone').append(employee.TenantPhoneNumber);
}
}
Then my html page containing textfield is
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div id="tenantcontactTP" data-role="page" data-add-back-btn="true">
<div data-role="content">
<ul data-role="listview" data-inset="true">
<form>
<table>
<tr><td>Phone Number</td><td><input type="text" name="tphone" id="tphone" value=""/></td></tr>
</table>
</ul>
<input type="submit" name="update" value="Update" />
</form>
</div>
</div>
</body>
</html>
I will update phone number. Phone number is showing if i use list, but not showing in text field
. What can I do?
2 Answers 2
Use $('#tphone').val(employee.TenantPhoneNumber);
to add a value to the text field
2 Comments
$('#tenantcontactTP').live('pageshow', function(event)
with $('#tenantcontactTP').live('pagecreate', function(event)
You want to set the input element's value, rather than appending. Use the following:
if (employee.TenantPhoneNumber) {
$('#tphone').val(employee.TenantPhoneNumber);
}