View Full Version : Question about working with onclick()

12-14-2007, 09:42 PM
Im just getting into javascript and am wondering if it is passable to have a single
button on a page, lets call it roll. Is there a way for me to set it up
so that each time i push that button it will run a function, which is get a random number from 1 - 12 but leave any previous number on the screen. sorta like this

No clicks yet

One Click

Two Click

Sorry for the diagram just trying to make my question as clear as possible.

12-15-2007, 03:00 AM
<script type="text/javascript">
function roll(){
var val = '';
var textobj = document.getElementById('rollid');
val = textobj.innerHTML;
val = val + ' ' + Math.floor(Math.random()*12+1);
textobj.innerHTML = val;

<input type="button" value="Roll" onclick="roll();"/>
<div id="rollid"></div>

best regards

12-16-2007, 07:29 AM
dude thank you soo much. I finished most of the program but for some reason i just couldnt get that bit there.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum