View Single Post
Old 04-25-2009, 05:26 PM   #16 (permalink)
Kalle
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
Why the heck is my code being printed to the screen? I am using the latest code that Kalle provided. And I am printing it out like this:


Code:
<script type="text/javascript">
	document.write(checkbox_count);
	</script>
Thats because checkbox_count is a function, and if you pass a function as a variable (a closure, I think Salathe covered this in a post of his) then it will print the closure's source. so I think what You want is to use:

javascript Code:
document.write(checkbox_count());

Assuming that checkboxes_count() ofcourse returns a numeric value for use here.


Instead of using document.write, you can always do a:
HTML Code:
<p>Times clicked: <span id="count">0</span></p>
<input type="button" onclick="++document.getElementById('count').innerHTML;" value="Bingo!" />
And have a <span> or <div> with an id/name given and then update the value which avoids embedding these <script> tags and then makes the code much cleaner and easier to work with.
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote