Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hide Email Address In img src

    I have an email address list that is dynamically genereated from an SQL Database. I want to write the address into a MAILTO: image using javascript, but can't figure out how to incorporate my ASP into the code.

    I am using the JS here http://javascript.internet.com/page-...ermeasure.html

    Here is my code but it doesn't work:

    Code:
    'receive value from DB
    <%= oRs.Fields("email") %>
    
    '=========================
    
    <script language="JavaScript"><!--
    
    // hide script
    <% Dim email as String
    email= oRs.Fields("email")
    if(email.IndexOf("@")>0){
    %>
        var sb_domain = "<%=email.Substring(email.IndexOf("@") + 1)%>";
        var sb_user = "<%=email.Substring(0, (email.IndexOf("@") + 1))%>";
        var sb_recipient = sb_user + sb_domain;
        var sb_url = "mailto:" + sb_recipient;
        document.write('<a href="'+sb_url+'"><img src="http://somesite.com/email1.jpg" border="0"/> </a>');
    <%}%> 
    // --></script>

    can someone help me write this, I getting loads of Microsoft VBScript errors. OR does anyone have a script that already functions?

    Thanks!!!!

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Is this classic asp using VBScript as your server-side language?

    If yes then you do not have either of these ( .Substring .IndexOf) available

    IF you are using ASP.NET then you do have them

    In classic asp use something similar to this
    Code:
    if(inStr(1,email,"@")>0)
    %>
       var sb_domain = "<%=Right(email,Len(email) - inStr(1,email,"@"))%>";
        var sb_user = "<%=Left(email,Len(email) - inStr(1,email,"@")+ 1)%>";
        var sb_recipient = sb_user + sb_domain;
        var sb_url = "mailto:" + sb_recipient;
        document.write('<a href="'+sb_url+'"><img src="http://somesite.com/email1.jpg" border="0"/> </a>');
    // --></script>
    Also VBScript does not use curly braces
    Last edited by miranda; 02-20-2007 at 10:47 PM. Reason: error in code

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is this classic asp using VBScript as your server-side language?

    If yes then you do not have either of these ( .Substring .IndexOf) available
    The script is a client side Javascript.


    I am using the JS here http://javascript.internet.com/page-...ermeasure.html

    Here is my code but it doesn't work:
    You are getting mixed up between client-side javascript and ouputted server-side code.

    Here is an example of what you wanted
    Code:
    <%While Not rs.EOF%>
    <script language="JavaScript">
    <!--// hide script
    
    email = '<%=rs("fieldName")%>';
    if(email.indexOf("@")>0){
        var sb_domain = email.substring(email.indexOf("@") + 1);
        var sb_user = email.substring(0, (email.indexOf("@") + 1));
        var sb_recipient = sb_user + sb_domain;
        var sb_url = "mailto:" + sb_recipient;
        document.write('<a href="'+sb_url+'"><img src="http://somesite.com/email1.jpg" border="0"/> </a>');
    }
    // -->
    </script>
    <%
    rs.MoveNext
    Wend
    %>

    imo you are going about this the wrong way. If javascript is disabled then your script will not work.

    You should setup a server-side form processing script to process emails.

  • #4
    New Coder
    Join Date
    Aug 2004
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    THANKs for everyone's feedback.

    degsy, your code works great, needed some minor adjustments, but is working!!
    Last edited by dude9er; 02-21-2007 at 05:28 PM.

  • #5
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by degsy View Post
    The script is a client side Javascript.


    Degsy relook at what he has for code. He had serverside and client side script mixed together. If you look at what his 1st post showed inside the asp delimiters then you will see that. because ASP can be done in JScript on the server is the reason why i asked that. He was definately mixing up the server and client side code

    In particular this was not VBScript even though it was in delimiters

    Code:
    <% Dim email as String 'only variable type availabe in VBScript is variant 
    email= oRs.Fields("email")
    if(email.IndexOf("@")>0){
    %>
    
    var sb_domain = "<%=email.Substring(email.IndexOf("@") + 1)%>";
        var sb_user = "<%=email.Substring(0, (email.IndexOf("@") + 1))%>";
    
    <%} %>
    Last edited by miranda; 02-21-2007 at 10:36 PM.

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just meant that the script trying to be incorporated was a client-side javascript. You can see from the link posted.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •