?
Solved

use .innerHTML in a echo statement in a php file

Posted on 2008-02-12
5
Medium Priority
?
733 Views
Last Modified: 2008-02-12
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
0
Comment
Question by:lilyyan
  • 3
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
darron_chapman earned 1200 total points
ID: 20876004
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
 

Author Comment

by:lilyyan
ID: 20876212
works great ! thanks a lot !

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

user onkeyDown action or other action?
0
 

Author Comment

by:lilyyan
ID: 20876276
namely, when user's first time input is incorrect and need to try again on the testform.php page
0
 
LVL 19

Assisted Solution

by:darron_chapman
darron_chapman earned 1200 total points
ID: 20876288
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
 

Author Comment

by:lilyyan
ID: 20876437
Great! Thanks a lot!
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question