2

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.

2
  • Can't get clearly what you actually want. Can you elaborate it? Commented Feb 20, 2016 at 5:41
  • @JyothiBabuAraja I am getting username displayed in div with id display_info.. I want to display username in input field udf1 as value... Commented Feb 20, 2016 at 5:43

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried this?

$('#udf1').val(response);

after

$( '#display_info' ).html(response);

May be this can help.

Comments

Your Answer

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.