how to display a message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    how to display a message

    how can i display a message(your cant register) when a link(<a href="#" onclick="show(' me')">Register</a>) is clicked below is my code

    Code:
    <html>
    <head>
    <title></title>
    <script type="text/javascript" charset="utf-8"> 
    function show(div){
    document.getElementById(div).style.display='';
    }
    
    </script> 
     </head>
    <body>
    <a href="#" onclick="show('me')">Register</a>
    <body>
     </html>
    Last edited by Niheel; Aug 23 '10, 08:15 PM. Reason: fixed code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    ?? ... you could put a simple alert or unhide a prepared div or create a new div and add the message etc. ... there are multiple options to display a message ... what do you exactly want to have?

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      Code:
       
      <html>
      <head>
      <title></title>
      <script type="text/javascript" charset="utf-8"> 
      function show(){
      alert('You cannot register');
      }
       
      </script> 
       </head>
      <body>
      <a href="#" onclick="show()">Register</a>
      <body>
       </html>

      Comment

      • simon2x1
        New Member
        • Dec 2008
        • 123

        #4
        i replace alert with documemt.write to show the message it did but it go back to register i want to display the message inside the body tab in html

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          [CODE=JAVASCRIPT]
          function showMesage(str) {
          if(document.get ElementById('al ert').style.dis play=='none'){
          document.getEle mentById('alert ').style.displa y='block';
          document.getEle mentById('alert ').innerHTML+=' <div style='text-align:center'>' str;
          }else{
          document.getEle mentById('alert ').style.displa y='none';
          document.getEle mentById('alert ').innerHTML="< input type='button' name='close' id=close' value='' onclick='showMe sage()' class='close' />";
          }
          return false;
          }
          [/CODE]
          [CODE=CSS]
          #alert{
          width:500px;
          height:200px;
          z-index:100;
          position:absolu te;
          margin:0 auto;
          left:25%;
          top:15%;
          font-family:Arial, Helvetica, sans-serif;
          font-weight:normal;
          font-size:12px;
          color:#900;
          border:5px dashed #FFF;
          background:#CCC
          }
          .close{
          border:0px;
          background: url(close.png) left top no-repeat #FFF;
          width:36px;
          height:37px;
          font-size:11px;
          cursor:pointer;
          }
          [/CODE]
          [CODE=HTML]
          <input type="button" name="show" id="show" value="Show Alert" onclick="showMe sage('This is my message')" />
          <div id="alert" style="display: none;">
          <input type='button' name='close' id='close' value='' onclick="showMe sage()" class='close' />
          </div>
          [/CODE]

          Comment

          • simon2x1
            New Member
            • Dec 2008
            • 123

            #6
            it still did not work this is what i did below
            Code:
             <html>
             <head>
             <title>page</title>
             <script type="text/javascript" charset="utf-8"> 
             function showMesage(str){
                         if(document.getElementById('alert').style.display=='none'){
                             document.getElementById('alert').style.display='block';
                             document.getElementById('alert').innerHTML+='<div style='text-align:center'>'str;
                         }else{
                             document.getElementById('alert').style.display='none';
                             document.getElementById('alert').innerHTML="<input type='button' name='close' id=close' value='' onclick='showMesage()' class='close' />";
                         }
                         return false;
                     }
            
             </script>
            <style type="text/css"> 
            #alert{
                 width:500px;
                 height:200px;
                 z-index:100;
                 position:absolute;
                 margin:0 auto;
                 left:25%;
                 top:15%;
                 font-family:Arial, Helvetica, sans-serif;
                 font-weight:normal;
                 font-size:12px;
                 color:#900;
                 border:5px dashed #FFF;
                 background:#CCC
             }
            .close{
                 border:0px;
                 background: url(close.png) left top no-repeat #FFF;
                 width:36px;
                 height:37px;
                 font-size:11px;
                 cursor:pointer;
             }
            </style> 
              </head>
             <body>
             <input type="button" name="show" id="show" value="Show Alert" onclick="showMesage('This is my message')" />
             <div id="alert" style="display:none;">
                     <input type='button' name='close' id='close' value='' onclick="showMesage(str)" class='close' />
                 </div
             <body>
              </html>

            Comment

            • omerbutt
              Contributor
              • Nov 2006
              • 638

              #7
              change the line no 8 to this
              document.getEle mentById('alert ').innerHTML+=s tr;

              Comment

              Working...