#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0

    Help with operation


    Hy all what i am trying to do is:
    -I have a site with a cart image at top and a 0 next to it
    I want when user press the image add to cart the 0 transform in 1 and so on ...... i have tried to concatenete but he display the 2 values 0 and 1

    Thanks in advance
    i did it if anyone want to know
    Code:
    <html>
    <head>
      <title></title>
    </head>
    <body>
    <div id="DIV1">
      9
    </div>
    <script type="text/javascript">
    
       var MyDiv1 = document.getElementById('DIV1');
       
       var my = parseInt(MyDiv1.innerHTML);
       alert(my);
       MyDiv1.innerHTML = (my + 1);
    
    </script>
    </body>
    </html>
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    you can't just use html_content + 1, because html_content is a string, and this will turn the addition into string concatenation. You have to convert the string into an integer first: parseInt().
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0
    i just did....but thaks for your help
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Acording to the Mozilla developer network (the link I gave you), you should specify the radix in the parseInt() function:

    javascript Code:
    var my = parseInt(MyDiv1.innerHTML, 10);
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    21
    Rep Power
    0
    If i put that "10" doesn't work and sometimes not with my code sometimes it works sometimes no why?? And how i can kep the number even if the user change the page??

IMN logo majestic logo threadwatch logo seochat tools logo