Eric McWinNer Eric McWinNer - 1 year ago 43
jQuery Question

How can I have a form where the text in the input remains when it's been clicked?

I was practicing PHP. I'm a learner. I'm just trying to find out how to make the info left in the input remain there when clicked, for special purposes. I tried using jquery to make that possible but it's not working.

Here's my html

<form method="post">
<label for="name">Name</label>
<input name="name" type="text" id="" placeholder="First Name" />
<input type="submit" value="submit now" id="submission" name="submit_now" />

Here's my PHP


$Admin = array("Eric", "Emeka", "Faith", "Lucy", "Theressa", "Hillary", "Justice", "Kate", "Rob");
$Users = array("Jonah", "Augustar", "Orma", "Edwin", "Kirk Franklin", "Michael Jackson", "Hopsin", "Nike");
$blacklist = array("Kenny", "kenny");
$key = 1;

if ($_POST["submit_now"]){
foreach($Admin as $val){
if ($_POST["name"]==$val){
echo "I know you ".$_POST["name"]." You're actually an Admin and have an awesome place in your own life or someone else's life";

$key = 1;
foreach($Users as $vall){
if ($_POST["name"]==$vall){
echo "I know you".$_POST["name"];
$key = 2;
foreach($blacklist as $valll){
if ($_POST["name"]==$valll){
echo "You've been banished ".$_POST["name"]." Leave and never return!";
$key = 3;
if ($key!=1 AND $key!=2 AND $key!=3){
echo "<b style=\"color:red\">Sorry I don't know you...";


And there's my jQuery

var a = $("#name").val();
$("#name").attr("val", "a");


Please just let me know where I went wrong

Answer Source

If you want keep value entered in the input box after form submit, you can try like this

<input name="name" type="text" id="" value="<?php echo $_POST['name']; ?>" />