Hey, I have, what I think is an easy situation to solve. I am trying to have variables dynamically written to html depending whether a checkbox is ticked.

This is what I have right now - if someone might also know the proper way to write this it would be very much appreciated...

$(document).ready(function(){
       if ($("#addon1").is(":checked")){
            var a = 10;
	   }else{ var a = 0;
	   } 
       document.getElementById('total').innerHTML = a;
	   });

Than I have a div with id of 'total' - When the document loads it does print 0 but when #addon1 is checked it does not change to 10 - But when I refresh it does go to 10.

How can I have it update automatically? Thanks a lot for any help at all.

the code is not complete all the elements referred to are not shown
for a div, that code should work
if total is an <input> the correct form would be document.getElementById('total').value = a; code samples should include all the elements referred to, otherwise its just a guess, if this scrap doesnt help repost the full code

Hey almost bob, I did throw yours in but I didnt get anything,. but than again im not outputting to an input field like you said.

sorry bout that here is the rest.

The input checkbox

<input type="checkbox" name="addon1" id="addon1" value="contactform" /> Contact Form<br />

The Div.

<div id="total"></div>

In order for the number to change on the fly, without needing to refresh, would i need to somehow refresh the div, or should I have the script write to a text input field?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.