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 13 of 13
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Show Text Only if Pound Sign Does Now Show

    I have this code:

    Code:
    <p id="checkout_notification_text" style="display:none;margin-top:-7px;"><b>As you are viewing prices in a currency other than GBP, prices shown will be converted into GBP by your card processor when payment is taken. This card processor <i>may</i> add a currency conversion fee of up to 2.5%.</b></p>
    What JS code would I need to display the above message only if a Pound sign (£) does NOT show? That pound sign being anywhere on the web page.

    Thank you.

  • #2
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    I think this should work.

    Code:
    <script type="text/javascript">
    document.getElementById('checkout_notification_text').style.display = document.body.textContent.search(/\u00A3|&pound;/) !== -1 ? 'none' : '';
    </script>
    Be sure to put that tag at the end of the <body> (inside, of course).

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thanks for your reply but unfortunately no luck. It won't show the text regardless of a pound sign or not. Any amendments I could try to the code?

    Does display:none still need to be in the initial code? I have tried both ways.

    Thanks

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    your javascript file also has some CSS in it as well. Id suggest you take a look at the included css to fix it.

  • #5
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    Wow. I'm sorry, that was my fault. I forgot that putting a script tag in the <body> counted to its textContent, so it was always hiding your DIV.

    Remove the first <script> tag I gave you, and put this one in the <head> tag.

    Code:
    <script type="text/javascript">
        window.addEventListener('load', function (event) {
            document.getElementById('checkout_notification_text').style.display = document.body.textContent.search(/\u00A3|&pound;/) !== -1 ? 'none' : '';
        }, false);
    </script>

  • Users who have thanked joesimmons for this post:

    brat42 (09-30-2013)

  • #6
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thanks very much, expert!

  • #7
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Just one other question if you don't mind. If I wanted to find GBP instead of the pound sign in the body of the text to finding, would I just have to change:

    Code:
    ...textContent.search(/\u00A3|&pound;/)...
    To:

    Code:
    ...textContent.search(GBP)...
    Many thanks.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Wouldn't you know where on the page the pound sign or GBP is? It is more efficient to look up on specific element(s) rather than the whole body content.

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Or there should be an info somewhere (in html or javascript) embedded by the server-side language that explicitly indicates the currency being used.

    I don't know how the page is set up so I'm just guessing here.

  • #10
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by brat42 View Post
    Just one other question if you don't mind. If I wanted to find GBP instead of the pound sign in the body of the text to finding, would I just have to change:

    Code:
    ...textContent.search(/\u00A3|&pound;/)...
    To:

    Code:
    ...textContent.search(GBP)...
    Many thanks.
    Very close. Just gotta add some quotes.

    Code:
    ...textContent.search("GBP")...

  • #11
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    I am happy with searching the whole body field but I was wondering if my code amendment was right as it does not appear to work. Due to the software company I am with, it is only JS I can add / I cannot go server side. The post I thanked did the job but I am having trouble replicating this on our mobile template.

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Searching through the body content may not be accurate as content of inline <script> tags inside the body will be included in the document.body.textContent and one or more of the scripts may have the string "GBP" or "\u00A3|&pound;" in it.

  • #13
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thanks very much for your replies. I am happy with document.body.textContent as I am aware of how this will be used and in what possible circumstances.

    After a few hours testing, I think I may have to fork out and get our developer again.

    It works in desktop but I cannot get our mobile template to work with using "GBP" (GBP being better than the pound sign). To check what the issue could be, I changed the desktop template to "GBP" and found the text would not show regardless of GBP being in the source code or not.

    This would indicate I am using the wrong code for the mobile template I modified of "GBP" instead of "/\u00A3|&pound;/". Even when I type in 20 random characters, the text still does not show indicating some problem with the code I think?! The code is basically saying these 20 random characters I type in are being met somewhere in the source code.


  •  

    Posting Permissions

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