Trying to add a link to 'alert_text'

Discussion in 'JavaScript' started by chrisj, Oct 1, 2009.

  1. #1
    I'm using this script which restricts uploading until a fee is paid.
    When the user selects the upload button the 'alert-text' from this script(below) pops-up with a message. That's works successfully.

    However, I tried to add a link to the message, and when I retried it, the message and the requirement was skipped altogether. When I removed the link from the message, all was well again, the message popped-up as before.

    Why, in the this line of code below:

    document.getElementById('alert_text').innerHTML =
    Code (markup):
    can't I add a link to that line and still have it perform successfully? Any ideas? Thanks.

    <script>
              //
              function takeAction()
              {
                if (document.getElementById('upload_permission').innerHTML == "Y")
                {
                  window.location.href = "/upload.php";
                }
                else
                {
                  alert(document.getElementById('alert_text').innerHTML);
                  return false;
                }
              }
              //
              var member_credits = document.getElementById('member_credits').innerHTML;
              var upload_permission = document.getElementById('upload_permission').innerHTML;
              //
              if (upload_permission == "")
              {
                document.getElementById('upload_credit').innerHTML = "";
                document.getElementById('upload_restrictions').innerHTML = "You cannot upload videos without first logging in.<br>";
                document.getElementById('login_request').innerHTML = "If you have not already logged in, please do that first.";
                document.getElementById('alert_text').innerHTML = "Please log in before attempting an upload.";
              }
              else if (upload_permission == "Y")
              {
                document.getElementById('upload_credit').innerHTML = "Your upload credit is on file.<br>";
                document.getElementById('upload_restrictions').innerHTML = "You may use this webpage to upload videos.";
                document.getElementById('login_request').innerHTML = "";
                document.getElementById('alert_text').innerHTML = "";
              }
              else
              {
                if (upload_permission.length > 1)  // referrer send back more than just a flag!  -JG
                {
                  document.getElementById('upload_credit').innerHTML = "*** " + upload_permission + " ***";
                  document.getElementById('upload_restrictions').innerHTML = "";
                  document.getElementById('login_request').innerHTML = "";
                  document.getElementById('alert_text').innerHTML = upload_permission + "\r\nPlease contact the webmaster for assistance.";
                }
                else
                {
                  document.getElementById('upload_credit').innerHTML = "No update credits on file.<br>";
                  document.getElementById('upload_restrictions').innerHTML = "You need to <a href='uploadfee.php' style='text-decoration:underline;'>purchase 1 upload credit</a> to upload videos.<br>";
                  document.getElementById('login_request').innerHTML = "";
                  document.getElementById('alert_text').innerHTML = "Please click on the 'purchase 1 upload credit' link to pay upload fee.";
                }
              }
            </script>
            <!-- ========================================================== 
    Code (markup):
     
    chrisj, Oct 1, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    you should be able to add a link easily,
    
    document.getElementById('alert_text').innerHTML = "<a href='link.html'>Link</a>";
    
    Code (markup):
    Doesn't work?
    Please show the script after you have added the link modifications.
     
    camjohnson95, Oct 1, 2009 IP
  3. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thanks for your reply. I added your suggestion:


    document.getElementById('alert_text').innerHTML = "<a href='link.html'>Link</a>";
    Code (markup):
    And when the pop-up message appears it shows this:
    "<a href='link.html'>Link</a>"

    instead of just: Link

    Is there a way to not show the link code?

    Thanks.

        <div id="column-wide">
    
          <div id="generic-container">
    
          <!--*********DO NOT EDIT ABOVE THIS LINE**********-->
    
          <h1 style="border-bottom:1px solid #dddcdc;"></h1>
    
            <p></p>
    
            <p></p>
    
            <!-- ========================================================== -->
            <!-- Control of user uploads based on payment information.  -JG -->
            <p>
              <div style="border:2px solid #dddcdc; margin:10px; padding:10px; width:400px;">
                <span id="member_credits" style="display:none;">[var.member_credits]</span>
                <span id="upload_permission" style="display:none;">[var.upload_permission]</span>
                <span id="alert_text" style="display:none;"></span>
                <span id="upload_credit"></span>
                <span id="upload_restrictions"></span>
                <span id="login_request"></span>
              </div>
            </p>
            <!-- -->
            <script>
              //
              function takeAction()
              {
                if (document.getElementById('upload_permission').innerHTML == "Y")
                {
                  window.location.href = "/upload.php";
                }
                else
                {
                  alert(document.getElementById('alert_text').innerHTML);
                  return false;
                }
              }
              //
              var member_credits = document.getElementById('member_credits').innerHTML;
              var upload_permission = document.getElementById('upload_permission').innerHTML;
              //
              if (upload_permission == "")
              {
                document.getElementById('upload_credit').innerHTML = "";
                document.getElementById('upload_restrictions').innerHTML = "You cannot upload videos without first logging in.<br>";
                document.getElementById('login_request').innerHTML = "If you have not already logged in, please do that first.";
                document.getElementById('alert_text').innerHTML = "Please log in before attempting an upload.";
              }
              else if (upload_permission == "Y")
              {
                document.getElementById('upload_credit').innerHTML = "Your upload credit is on file.<br>";
                document.getElementById('upload_restrictions').innerHTML = "You may use this webpage to upload videos.";
                document.getElementById('login_request').innerHTML = "";
                document.getElementById('alert_text').innerHTML = "";
              }
              else
              {
                if (upload_permission.length > 1)  // referrer send back more than just a flag!  -JG
                {
                  document.getElementById('upload_credit').innerHTML = "*** " + upload_permission + " ***";
                  document.getElementById('upload_restrictions').innerHTML = "";
                  document.getElementById('login_request').innerHTML = "";
                  document.getElementById('alert_text').innerHTML = upload_permission + "\r\nPlease contact the webmaster for assistance.";
                }
                else
                {
                  document.getElementById('upload_credit').innerHTML = "No update credits on file.<br>";
                  document.getElementById('upload_restrictions').innerHTML = "You need to <a href='uploadfee.php' style='text-decoration:underline;'>purchase 1 upload credit</a> to upload videos.<br>";
                  document.getElementById('login_request').innerHTML = "";
                  document.getElementById('alert_text').innerHTML = "<a href='link.html'>Link</a>";
                }
              }
            </script>
            <!-- ========================================================== -->
    
            <p></p>
    
            <p></p>
    
    
            		        		<div class="container4"><font size="3" color="#000000" face="Arial">UPLOAD</font><br><br>
    <p><br>
    								<a href="/uploader_1.php"><img src="themes/default/images/sp_1.jpg" alt="" /></a>
    						         <br>
    						      </div>
    
    				        		<div class="container5">
    								Header<br><br>
    		</div>
    
    
    				        		<div class="container6"><font size="3" color="#000000" face="Arial"></font><br><br>
    </p><br>
    		         <a href="/upload.php" onclick="takeAction(); return false;"><img src="themes/default/images/sp_1.jpg" alt="" /></a>
    						         <br>
    
    		      </div>
    
    
          <!--*********DO NOT EDIT BELOW THIS LINE**********-->
    
          </div>
    
        </div>
    Code (markup):
     
    chrisj, Oct 2, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    No I don't think that you can put a link in a window alert.
     
    camjohnson95, Oct 2, 2009 IP
  5. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    Thanks for your reply.
    Any way to change it to a pop-up box or mouseover box?
     
    chrisj, Oct 2, 2009 IP
  6. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Could you just display a bold red box with the message inside?
     
    camjohnson95, Oct 2, 2009 IP
  7. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #7
    well you could make it a confirm() instead.

    like confirm("Would you like to go to www.foo.com now?"); would result in this as a question with OK / CANCEL and boolean return.


    for example, if (confirm("yes or no")) window.location.href = blah;
     
    dimitar christoff, Oct 2, 2009 IP