From what I have read, my variables should be dumping their data and getting new data when I call the function again. I cannot figure out why my code isn't doing this though.
When the page first loads everything seems to be working. The function runs, and it grabs the price/qty. When I click .switcher-label, or any of the other elements listed below it doesn't change the variables though. They just stay the exact same as they were when the page first loaded. I have no idea what is going on here, I went as far as running an if statement to check if the price is above 0 and setting everything to null if it was, but it still didn't change anything.
Thanks in advance for your help.
- <script type="text/javascript">
-
- var bessie = function(){
-
- //Pull html code for plus/minus qty selector
- var qtyCode = jQuery('.qtyswitcher-qty').html();
-
- //Get value of qty that is currently selected
- var qty = jQuery('#qtyswitcher-qty').val();
-
- //Pull the current price and change the string to a number
- var price = jQuery('.price').first().text().replace(/[^0-9\.]+/g,"");
-
- //multiply price by qty to get the total for the users current selection
- var total = price * qty;
-
- //New html that will be inserted into the page
- var newContent = '<p class="multiply">' + '$' + price + '/ea</p>' + '<p class="multiply2">x</p>' + '<div id="qty">' + qtyCode + '</div>' + '<p class="multiply3">=</p> <p class="multiply">' + '$' + total.toFixed(2) + '</p>';
-
- //New html being inserted
- jQuery(".qtyswitcher-qty").replaceWith(newContent);
- };
-
-
- bessie();
- jQuery('.switcher-label').click(bessie());
- jQuery('#qtyswitcher-oneless').click(bessie());
- jQuery('#qtyswitcher-onemore').click(bessie());
-
- </script>