Posts filed under ‘non php code’

simple flip image javascript

sometimes you want an image to change when you select a different option in a dropdown, i used to do it the hard way:
function flip() { document.images.x.src="themes/x/"+ document.reg.thememem.options[document.reg.thememem.selectedIndex].value+".gif"; }

i had to write a new js function for every new dropdown i use. so i looked for an easier way and wrote something:
function flip(image_id, select_name) { document.getElementById(image_id).src = select_name.options[select_name.selectedIndex].value }

to use it, do something like:
<select name="myselect" onchange="flip('myImage', this)"> <option value="images/candle.gif">candle</option> <option value="images/coin.gif">coin</option> <option value="images/earth.gif">earth</option> </select> <img id="myImage" src="images/balloons.gif">

obviously if you want to call it a second time, just pass a different image_id to it and make sure it matches the id attribute of your second img tag :)

return to top link without bookmark

i saw this on leslie’s site. i never thought of it before. the conventional way to do a “return to top” link is create a bookmark with:
<a name="top"></a>

at the top of the page and then use:
<a href="#top">Return to Top</a>
to link it.

well there’s an easier way. this only works if you want to return to the very top of the page. it obviously does not replace the functionality of bookmarks.

<a href="#" onclick="window.scrollTo(0,0);return false;">Return to Top</a>

Since the latter one uses javascript therefore it will not work on browsers with javascript disabled.

Page 3 of 3«123