PDA

View Full Version : Style Sheet Switcher don't remember selection in drop down list



coolguy
11-27-2007, 03:53 PM
1) Script Title: Styyle Sheet Switcher

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm

3) Describe problem: I am using a drop down list to select alternative css files. Upon changing to another style, the page is styled nicely. Close the browser then go back to the same url (www.viewspot.net/family). Last selected style is applied, but drop down list item selected does not.

Site url: www.viewspot.net/family

Change the style on the drop down list at the top. Close the browser, then go back to it. Style remains, drop selection don't.

ddadmin
11-28-2007, 01:32 AM
In order for the select box to match the currently persisted style, you need to call the optional indicateSelected() function. This is described on the script page actually:

"Finally, if you're using radio buttons or a select menu for the switch interface, you can let the script automatically check/select the radio buttion/select option that corresponds to the currently applied alternate style sheet when the page loads. So lets say the user had chosen "Blue theme" a few days ago. Upon his return, the script can check the "Blue theme" choice inside the HTML automatically. To do this, add the below little script to the HEAD section of your page:


<script type="text/javascript">
window.onload=function(){
var formref=document.getElementById("switchform")
indicateSelected(formref.choice)
}
</script>

where "switchform" is the ID of the form of the switch interface, and "choice", either the name of the radio buttons or select menu. If the switch interface appears on all pages of your site, consider moving the above script inside "styleswitch.js"."

coolguy
11-28-2007, 08:09 PM
Thanks for the speed reply. I have included the code you mentioned but it is throwing an error:

Line 167
Error: 'type' is null or not an object

http://www.viewspot.net/family

ddadmin
11-29-2007, 12:18 AM
Try changing:


indicateSelected(formref.choice)

to:


indicateSelected(formref.switchcontrol)

to correctly reflect your SELECT element's name attribute.

coolguy
11-30-2007, 03:21 PM
Try changing:


indicateSelected(formref.choice)

to:

indicateSelected(formref.switchcontrol)

to correctly reflect your SELECT element's name attribute.

Thank you very much. Your hep was great and very quick. Top man!