0

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?

automaticAllDramatic
2,0831 gold badge21 silver badges25 bronze badges
asked Sep 13, 2012 at 11:24
0

2 Answers 2

1

Use $('#tphone').val(employee.TenantPhoneNumber); to add a value to the text field

answered Sep 13, 2012 at 11:28
Sign up to request clarification or add additional context in comments.

2 Comments

not working bro!!before i can show in a list but now not in list nor in textfield.
Try replacing $('#tenantcontactTP').live('pageshow', function(event) with $('#tenantcontactTP').live('pagecreate', function(event)
0

You want to set the input element's value, rather than appending. Use the following:

if (employee.TenantPhoneNumber) {
 $('#tphone').val(employee.TenantPhoneNumber);
}
answered Sep 13, 2012 at 11:30

2 Comments

not working bro!!before i can show in a list but now not in list nor in textfield
can u ppl use the proper wording: JavaScript and jQuery?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.