Random image with javascript -
without knowing javascript @ somehow created random image generator:
<script language="javascript"><!-- document.write("<img src=\"image-"+math.floor(math.random()*12+1)+".jpg\" />"); //--></script>
i show random images should there limitations need help.
- sometimes have more 9 images pages , name "mad-01", "mad-02"... "mad-11" keep them sorted code above can't show images 0 before second digit. have named images , without 0 before second digit: "mad-01", "calm-1". how can solved? or better remove 0 images?
- is there way make code way won't need keep writing how many images there show?
i have code shortest possible that's why i'm not using array.
i removing 0 file names easiest solution. depends on whether need or not.
not sure mean here. javascript can't detect how many images there in file system on own. if you're using kind of server side language might have functionality counting files, , print value javascript code.
if want keep leading zeros in file names, this:
<script language="javascript"><!-- var number = math.floor(math.random()*12+1); if(number < 10) number = "0" + number; document.write("<img src=\"image-"+number+".jpg\" />"); //--></script>
Comments
Post a Comment