use .innerHTML in a echo statement in a php file

hello

this is two file i used
------------------------
testform.php
<form method="post" action="doForm" >
user name <input type="text" name="userName" id="userNameID" />
<span id="userConfirm"></span>
<input type="submit" value="Submit">
---------------------------

doForm.php
if the user name doesn't exist, then i use the following two line:
--------------------------------------------------
if ( username doesn't exist) {
include("testform.php");
        echo "<script language=Javascript>
        document.getElementById('userConfirm').innerHTML='User Name doesn't exist.';
        </script>";
}
----------------------------------------------------
the javascript doesn't work. seems like there is some error in the js file.
any suggestion about this?

Thanks very much,
lilyyan
lilyyanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

darron_chapmanCommented:
Try this instead...

testform.php
<form method="post" action="doForm" >
user name <input type="text" name="userName" id="userNameID" />
<span id="userConfirm"><?php echo $message;?></span>
<input type="submit" value="Submit">

doForm.php
if ( username doesn't exist) {
 $message="User Name doesn't exist";
  include("testform.php");
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lilyyanAuthor Commented:
works great ! thanks a lot !

is that possible when user start to type, set the $messsage="" ?

user onkeyDown action or other action?
0
lilyyanAuthor Commented:
namely, when user's first time input is incorrect and need to try again on the testform.php page
0
darron_chapmanCommented:
You can't change a php variable using javascript, because php is executed before the page reaches the client, and javascript is executed after... however you can change your text box to this..

<input type="text" name="userName" id="userNameID" onKeyDown="document.getElementById('userConfirm').innerHTML='';"/>

and it should work fine (worked for me in my tests)
0
lilyyanAuthor Commented:
Great! Thanks a lot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.