470,647 Members | 1,085 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

How display dynamic text string?

I would like to have a errorMessage displayed in a webpage. When a
function is called the text changes. My code below replaces the html
page with the errorMessage instead of embedding it into the html code.
Its a stripped down version of the actual code but contains the same 3
pieces: An action to validate a form, the function to check if the
form is valid, and a function to display the type of error. Any
suggestions? -Nick
<html>
<head>
<script language="JavaScript" type="text/JavaScript">

function isError(error) {
if (error == 'yes') displayError("There has been an error");
}

</script>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">

function displayError(errorMessage) {
document.write(errorMessage);
}

</script>
<a href="#" onClick="isError('yes')">Display Error</a>
</body>
</html>
Jul 23 '05 #1
4 4935
Nick wrote:
I would like to have a errorMessage displayed in a webpage. When a
function is called the text changes. My code below replaces the html
page with the errorMessage instead of embedding it into the html code.
Its a stripped down version of the actual code but contains the same 3
pieces: An action to validate a form, the function to check if the
form is valid, and a function to display the type of error. Any
suggestions? -Nick
<html>
<head>
<script language="JavaScript" type="text/JavaScript">

function isError(error) {
if (error == 'yes') displayError("There has been an error");
}

</script>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">

function displayError(errorMessage) {
document.write(errorMessage);
}

</script>
<a href="#" onClick="isError('yes')">Display Error</a>
</body>
</html>


Yeah... do something like this:

<SPAN id=errorMessageText></SPAN>

Then, in a script, you can do this:

<SCRIPT type="text/javascript">
function displayError(errorMessage) {
document.getElementById("errorMessageText").innerT ext = errorMessage;
}
</SCRIPT>

If you want more formatting than plain text, use innerHTML instead of
innerText

B

Jul 23 '05 #2
Exactly what I needed. Thanks so much Brian for taking the time to
post. You rock. -Nick
Jul 23 '05 #3
On Tue, 27 Apr 2004 07:16:22 -0400, Brian Genisio <Br**********@yahoo.com>
wrote:

[snip]
<SPAN id=errorMessageText></SPAN>

Then, in a script, you can do this:

<SCRIPT type="text/javascript">
function displayError(errorMessage) {
document.getElementById("errorMessageText").innerT ext = errorMessage;
}
</SCRIPT>

If you want more formatting than plain text, use innerHTML instead of
innerText


However, it is important to note that innerText isn't supported by the
Mozilla family of browsers (amongst others, no doubt). innerHTML is better
supported.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4
Michael Winter wrote:
On Tue, 27 Apr 2004 07:16:22 -0400, Brian Genisio
<Br**********@yahoo.com> wrote:

[snip]
<SPAN id=errorMessageText></SPAN>

Then, in a script, you can do this:

<SCRIPT type="text/javascript">
function displayError(errorMessage) {
document.getElementById("errorMessageText").innerT ext = errorMessage;
}
</SCRIPT>

If you want more formatting than plain text, use innerHTML instead of
innerText

However, it is important to note that innerText isn't supported by the
Mozilla family of browsers (amongst others, no doubt). innerHTML is
better supported.

Mike


Woops :) Yeah, I knew that. My bad.
Brian

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by K | last post: by
2 posts views Thread by Tyrone Slothrop | last post: by
7 posts views Thread by Mike Livenspargar | last post: by
reply views Thread by Barb | last post: by
reply views Thread by Andrť Nobre | last post: by
3 posts views Thread by c676228 | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.