View Full Version : show selected option when page loads

11-02-2013, 02:09 PM
You can change the background color from a div with a select menu.

TESTPAGE (http://www.stickers.be/X_Tests/Change_BC_Image/Change_BC_Image.asp)

The first option is "transparant", this is an image (white-gray cubes).
When the page loads the background-color is "white". Change it to e.g. "red".
Than you can change it to "transparant" en appears the image.

It should be the "transparant" option when the page loads.

Anyone an idea how to do this ?

11-02-2013, 04:23 PM
Put this right before the closing </body> tag:

<script type="text/javascript">
document.getElementById('colorBG').selectedIndex = 0;
window.onunload = function(){};

11-02-2013, 04:40 PM
Great ... thanks John !

Do I have to change something on the style :

<option value="url(Background-No.jpg)" selected="selected" style="background-color:White; color:#000000">Transparant</option>

11-02-2013, 04:49 PM
Not really. You could and probably should set it to what you want it to be on page load and you could/should set the background for the BackColor2 div to that as well. But the surest way, cross browser is the code I gave you. You should probably do both. But just the code is all you need if javascript is enabled, and the thing won't work if javascript is not available.

11-02-2013, 05:21 PM
OK thanks.

On my testpage everything works fine.
But on MY PAGE (http://www.stickers.be/detail-eigentekst-Afmeting.asp) there must be something wrong ...

11-02-2013, 06:18 PM
Looks like it's working there too. Looks like some other script is changing things after that. Ah, looks like (remove the highlighted):

<body onload="changeBG('WhiteSmoke');berekenAlles();load()">

There could also be other problems, but that's probably it, and that has to be removed for it to work the way you want it to anyway.

11-02-2013, 06:35 PM
yes that's it
I removed it in the code, but I had to remove it from the templates properties too.

Thanks John, you helped me a lot of times.
Remember this thread ? (http://www.dynamicdrive.com/forums/showthread.php?59588-get-pixel-dimensions-of-innerHTML&p=244063&highlight=#post244063)
The solution is also on THIS PAGE. Maybe you can use it ... . :)