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

    Removing Numbers from a Span

    Due to the restrictions of our e-commerce provider, we need to make this amendment within the front end HTML / JS section. Currently our site displays a stock level i.e "8 In Stock". The figure could be 4, the figure could be 800 or any other figure.

    We would like this figure to be removed. What would be the correct way using JS to remove the figure plus the space when the page loads? i.e the page should just show "In Stock".

    We have the following code (which is incorrect for the second line of JS):

    Code:
    <div id="checkboxes">
    
                        <p style=""><span class="VariationProductInventory"><img align="left" src="/product_images/uploaded_images/productcheck.jpg">8 In Stock</span></p>
                        <p><img align="left" src="/product_images/uploaded_images/productcheck.jpg">Worldwide Delivery</p>
                        <!---<p><img align="left" src="/product_images/uploaded_images/productcheck.jpg" />Ships within 24 hours</p>--->
                        
                        <script type="text/javascript">
                            $('#checkboxes p span').remove(":contains('Sold')");
                            &lt;!--$('.VariationProductInventory').html($('.VariationProductInventory').html().replace("7","")--&gt;
                            );
                        </script>
                    </div>
    Any help much appreciated.

    Thank you
    Last edited by brat42; 04-03-2013 at 02:21 PM.

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    foo.replace(/">[0-9]+ /,'">')

    this won't work?
    Last edited by patryk; 04-03-2013 at 03:03 PM.

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Sorry I haven't got a clue with JS. Would you mind please adding / editing the code I gave you to the one we need?

    Thanks very much.

  • #4
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    are all spans you want to process with "VariationProductInventory" class?
    all of them will have image inside?

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #5
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    are all spans you want to process with "VariationProductInventory" class?
    all of them will have image inside?
    You are correct. Thank you.

  • #6
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    gere you go.
    Code:
    function stripNumbers(){
    	$('.VariationProductInventory').each(function(){
    		$(this).html($(this).html().replace(/">[0-9]+ /,'">'));
    	});
    }
    you have to call this function on page load

    here you have example how: http://freedockstar.com/jsreplace.php

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #7
    New Coder
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thanks very for that but is there a way to do this without calling it on page load? The reason I ask is that the number can be seen for a split second by the web visitor.

    Thank you

  • #8
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    you can call it right after every span you want to process(to perhaps save few milliseconds)
    but you should do it server-side. why output data you don't want to display in the first place?

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Perhaps the OP doesn't have that much control.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #10
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    Quote Originally Posted by WolfShade View Post
    Perhaps the OP doesn't have that much control.
    can add javascript code to a file, but can't alter other part of the same file?....
    interesting theory indeed

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • #11
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Quote Originally Posted by brat42 View Post
    Due to the restrictions of our e-commerce provider, we need to make this amendment within the front end HTML / JS section.
    If the data is being dynamically generated, this implies (to me) that the OP doesn't have much control. IDK the environment, but the host appears to be paranoid.

    EDIT: .. or I could be completely off my rocker and the OP is actually a script-kiddie/wanna be hacker looking for security holes.
    Last edited by WolfShade; 04-03-2013 at 04:18 PM.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #12
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    it's easier to simply use CSS:

    Code:
    .VariationProductInventory {display: none; }
    if that css is in the <head>, the quantity will never be visible when the page is shown.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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