How display dynamic text string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick

    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="JavaS cript" type="text/JavaScript">

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

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

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

    </script>
    <a href="#" onClick="isErro r('yes')">Displ ay Error</a>
    </body>
    </html>
  • Brian Genisio

    #2
    Re: How display dynamic text string?

    Nick wrote:
    [color=blue]
    > 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="JavaS cript" type="text/JavaScript">
    >
    > function isError(error) {
    > if (error == 'yes') displayError("T here has been an error");
    > }
    >
    > </script>
    > </head>
    > <body>
    > <script language="JavaS cript" type="text/JavaScript">
    >
    > function displayError(er rorMessage) {
    > document.write( errorMessage);
    > }
    >
    > </script>
    > <a href="#" onClick="isErro r('yes')">Displ ay Error</a>
    > </body>
    > </html>[/color]

    Yeah... do something like this:

    <SPAN id=errorMessage Text></SPAN>

    Then, in a script, you can do this:

    <SCRIPT type="text/javascript">
    function displayError(er rorMessage) {
    document.getEle mentById("error MessageText").i nnerText = errorMessage;
    }
    </SCRIPT>

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

    B

    Comment

    • Nick

      #3
      Re: How display dynamic text string?

      Exactly what I needed. Thanks so much Brian for taking the time to
      post. You rock. -Nick

      Comment

      • Michael Winter

        #4
        Re: How display dynamic text string?

        On Tue, 27 Apr 2004 07:16:22 -0400, Brian Genisio <BrianGenisio@y ahoo.com>
        wrote:

        [snip]
        [color=blue]
        > <SPAN id=errorMessage Text></SPAN>
        >
        > Then, in a script, you can do this:
        >
        > <SCRIPT type="text/javascript">
        > function displayError(er rorMessage) {
        > document.getEle mentById("error MessageText").i nnerText = errorMessage;
        > }
        > </SCRIPT>
        >
        > If you want more formatting than plain text, use innerHTML instead of
        > innerText[/color]

        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.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Brian Genisio

          #5
          Re: How display dynamic text string?

          Michael Winter wrote:[color=blue]
          > On Tue, 27 Apr 2004 07:16:22 -0400, Brian Genisio
          > <BrianGenisio@y ahoo.com> wrote:
          >
          > [snip]
          >[color=green]
          >> <SPAN id=errorMessage Text></SPAN>
          >>
          >> Then, in a script, you can do this:
          >>
          >> <SCRIPT type="text/javascript">
          >> function displayError(er rorMessage) {
          >> document.getEle mentById("error MessageText").i nnerText = errorMessage;
          >> }
          >> </SCRIPT>
          >>
          >> If you want more formatting than plain text, use innerHTML instead of
          >> innerText[/color]
          >
          >
          > 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
          >[/color]

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

          Comment

          Working...