0

What I basicaly want to do is this: click on the checkbox and update the total value which is $5000. So if I click the two, it will be $5110, and if I uncheck the $60 for instance, it will drop to $5050.

.

I couldn't past the whole progress of my code, so I included it in my webpage in a css file: http://adroid.cl/js_problem.css.

I almost got this code done, but it has some bugs, and I would really appreciate I receive some guidance on this one, thank you!

3
  • In fact your CSS file is not correct. It should contain only CSS rules but not the whole code including markup and JavaScript. Commented Jan 19, 2013 at 18:43
  • @VisioN , i think he's saved it as a css file so it loads the source of the webpage he's not actually planning on linking it in his webpage and Herland next time just create a jsfiddle.net Commented Jan 19, 2013 at 20:12
  • @Yusaf it really worked, thank you! I updated your code to give it currency format, that was my last difficulty. jsfiddle.net/3n6Xu Commented Jan 20, 2013 at 4:02

1 Answer 1

1

http://jsfiddle.net/zmJ3k/

with no html included you will have to change some attributes

var input = document.getElementsByTagName("input");
var total = document.getElementById("total");
for(i=0;i<input.length;i++){
    input[i].onchange = function(){
        if(this.checked){
             total.innerHTML = parseFloat(total.innerHTML) + parseFloat(this.value);
        }else{
             total.innerHTML = parseFloat(total.innerHTML) - parseFloat(this.value);
        }
    }
}

http://jsfiddle.net/zmJ3k/1/

forgot about the $

var input = document.getElementsByTagName("input");
var total = document.getElementById("total");
for(i=0;i<input.length;i++){
    input[i].onchange = function(){
        if(this.checked){
             total.innerHTML = "$" + (parseFloat(total.innerHTML.split("$")[1]) + parseFloat(this.value));
        }else{
             total.innerHTML = "$" + (parseFloat(total.innerHTML.split("$")[1]) - parseFloat(this.value));
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

oops, just looked at your jquery file, but d.w it will work as normal
Thank you so much @Yusaf Khaliq it does update the price value. But I am having another difficulty, that is the currency format. I'm trying to add this format: 5.000 or 49.000 but I don't know where in the Javascript to add this function. I add total.formatMoney(0,'.',',') but it doesn't work
sorry that makes no sense to me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.