displaying message using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kumuda v
    New Member
    • Jul 2007
    • 21

    displaying message using javascript

    Hi all,

    I want to display a message when a link is clicked, just below it. How will I do it using javascript and html.

    With regards
    Last edited by kumuda v; Aug 23 '07, 09:36 AM. Reason: I got the solution for this problem
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Kumuda.

    I notice that in your edit reason, you mention that you found a solution to the problem. Is this correct?

    You can go ahead and post a reply in your threads if you find the answer you're looking for. As a courtesy to your fellow developers, it is also nice to post the solution so that if anyone else ever has this problem, he can read your thread and find out the solution.

    Comment

    • ashsa
      New Member
      • Feb 2007
      • 45

      #3
      Originally posted by kumuda v
      Hi all,

      I want to display a message when a link is clicked, just below it. How will I do it using javascript and html.

      With regards
      Code:
       
      <HTML>
      <BODY>
      <a href="[url="http://www.google.com/"]www.google.com[/url]" onclick='showMessage();'>
      Don't Click here
      </a><BR>
      <span id='msg'></span>
      </BODY>
      <script>
      <!--
      function showMessage()
      {
      var message="How dare you click me !!"
      document.getElementById('msg').innerHTML=message;
      //return false;
      }
      -->
      </script>
      </HTML>

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by ashsa
        Code:
         
        <HTML>
        <BODY>
        <a href="[url="http://www.google.com/"]www.google.com[/url]" onclick='showMessage();'>
        Don't Click here
        </a><BR>
        <span id='msg'></span>
        </BODY>
        <script>
        <!--
        function showMessage()
        {
        var message="How dare you click me !!"
        document.getElementById('msg').innerHTML=message;
        //return false;
        }
        -->
        </script>
        </HTML>
        Asha you are almost right but you better to use something like this.

        [code=html]
        <a href="javascrip t:void(0)" onclick='showMe ssage();'>
        Don't Click here
        </a>
        [/code]

        [code=javascript]
        var message="How dare you click me !!"
        document.getEle mentById('msg') .innerText=mess age;
        [/code]

        I think what am I talking about.
        Ok.

        Kind regards,
        Dmjpro.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by dmjpro
          Asha you are almost right but you better to use something like this.

          [code=html]
          <a href="javascrip t:void(0)" onclick='showMe ssage();'>
          Don't Click here
          </a>
          [/code]
          You should avoid using the Javascript protocol in link hrefs. It should point to a real link even if it be a #.
          Originally posted by dmjpro
          [code=javascript]
          var message="How dare you click me !!"
          document.getEle mentById('msg') .innerText=mess age;
          [/code]
          innerHTML is supported by most browsers I don't think innerText is.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            Originally posted by acoder
            innerHTML is supported by most browsers I don't think innerText is.
            yup ... MOZ/FF don't have innerText ... but do have innerHTML

            kind regards

            Comment

            Working...