Reputation: 2397
I have two scripts....
1. HTML Part :
<html>
<head>
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script>
function loaddata()
{
var email=document.getElementById( "email" );
var email1 = $(email).val();
if(email1)
{
$.ajax({
type: 'post',
url: 'form-inputs.php',
data: {
user_email:email1,
},
success: function (response) {
// We get the element having id of display_info and put the response inside it
$( '#display_info' ).html(response);
}
});
}
else
{
$( '#display_info' ).value("Please Enter Some Words");
}
}
</script>
</head>
<body>
<input name="email" id="email" onkeyup="loaddata();" required/>
<br><br>
<input name="udf1" id="udf1" readonly="readonly"/>
<br>
<div id="display_info" ></div>
</body>
</html>
2. form-inputs.php :
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die("Could not connect: " . mysql_error());
}
mysql_select_db("databasename", $con);
##############################
if( isset( $_POST['user_email'] ) ){
$emailfetch=$_POST['user_email'];
$sqlraw = "select username, email from registration where email = '$emailfetch' ";
$sql=mysql_query($sqlraw);
while($row=mysql_fetch_array($sql)){
if(isset($row['email'])){
echo $row['username']; //shown only if post email exists in database
}else{
echo "Check Email Again";
}
}
}
?>
With these codes, I am getting username shown properly in div with id display_info
. .
But I want to use and set this username value in my second udf1
input field.
Help appreciated.
Upvotes: 2
Views: 1336
Reputation: 498
Have you tried this?
$('#udf1').val(response);
after
$( '#display_info' ).html(response);
May be this can help.
Upvotes: 1
Reputation: 10292
Use this
echo '<input type="text" name="user" value="' . $row['username'] . '">';
instaead of this
echo $row['username']; //shown only if post email exists in database
Upvotes: 2