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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking Fields in a database

    I was wondering how would I go about doing the following in asp

    here is the code example what I want to do

    If RS("HttpLink") <>"" Then
    If RS("HttpLink") contains "Http" Then
    response.write "<P ALign=Center><a href=" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
    End If
    If RS("HttpLink") does not contain "Http" Then
    response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
    End If
    End If

    Changing the Contains and Does not contain to actual vbscript or asp script characters!

    Basically the httplink field will contain web addresses and some may contain the http:// header and some may not but when the dont and I dont add the http:// then the link doesnt work on the page!

    Any thoughts

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Assuming the links will be in either of these two forms:

    www.codingforums.com
    http://www.codingforums.com

    It is sufficient to just test the left four character to make sure they are "http". I converted them to lowercase so that it matches any case the user might enter (http, HTTP, Http, etc.)
    <%
    If RS("HttpLink") <>"" Then
    If lcase(left(RS("HttpLink")))="http" Then
    response.write "<P ALign=Center><a href=" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
    else
    response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
    End If
    End If
    %>

  • #3
    New Coder
    Join Date
    Jan 2003
    Location
    Peterborough, UK
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd do this:

    strLink = Replace(RS("httpLink"),"http://","")

    response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"

    This will remove all instances of http:// and replace with nothing.

    It might be better to use a simple function though, like this:

    Function removeHTTP(link)

    cleanLink = Replace(link,"http://","")
    cleanLink = Replace(cleanLink,"http:/","")

    {insert more here to replace any other possible misspellings of http://}

    removeHTTP = cleanLink

    End function

    The you would write to the page as:

    response.write "<P ALign=Center><a href=http://" & removeHTTP(RS.fields("HttpLink")) & " target=blank_>Click Here</a>"

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    51° 03' -78" N -114° 05' 72" W
    Posts
    617
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thankyou both for all the choices I will say that the only one that worked was the function one at the end so I am glad you added it the other 2 both of yours returned the following on the link
    http://†“³Ļ†¯†÷³Ö³ā/
    Aarnyinc yours returned the following first but i fixed that

    Microsoft VBScript runtime error '800a01c2'

    Wrong number of arguments or invalid property assignment: 'left'

    /Obituarys/Viewing_Obituary.asp, line 116
    but the fix was the following

    <%
    If RS("HttpLink") <>"" Then
    If lcase(left(RS("HttpLink"), http)) Then
    response.write "<P ALign=Center><a href=" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
    else
    response.write "<P ALign=Center><a href=http://" & RS.fields("HttpLink") & " target=blank_>Click Here</a>"
    End If
    End If
    %>
    but after i fixed it then i got the following above as i did with ravens first one not sure why thought!!!

    But dont get me wrong I am very thankfull for any support given and I just want to say thankyou

    P.s. I must be getting better at this as I was able to find the mistake and fix it without any help Yeah me


  •  

    Posting Permissions

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