| | |
form menu style sheet changer
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Put something like this in the head of every page: (note: you only really need the bold part in the code of the page with the form/that changes the cookie)
I can't really test that atall; I can't run ASP anywhere.
The principle will work but some of the keywords words might be wrong... (is it Form or Forms?/Cookie or Cookies?) Also; it's not very secure or input-safe. A better way would be to use a keyword/enumeration in the cookie and form, and set the style variable to one of a list of the only allowable values.
For that code to work you'll need to set Javascript as the script language.
(put this line before the code)
It'd almost be the same with VBScript; although I don't know how you'd test for a null string...
<%
var style = new String(Request.Cookies('style'));
if(style==null || style=='undefined'){
style = new String(Request.Forms('style'));
if(style==null || style=='undefined'){
style="default";
}else{
Response.Cookies('style') = style;
}
}
%>
<link rel="stylesheet" type="text/css" href="/styles/style_<%Response.write(style)%>.css"/>The principle will work but some of the keywords words might be wrong... (is it Form or Forms?/Cookie or Cookies?) Also; it's not very secure or input-safe. A better way would be to use a keyword/enumeration in the cookie and form, and set the style variable to one of a list of the only allowable values.
For that code to work you'll need to set Javascript as the script language.
(put this line before the code)
HTML and CSS Syntax (Toggle Plain Text)
<%@ LANGUAGE="JAVASCRIPT" %>
Last edited by MattEvans; Jan 25th, 2007 at 3:44 pm.
Plato forgot the nullahedron..
wow brilliant thanks! most people just put waffly replies with no real direction or instructions for newbies but urs was perfect!
and thanks for the fast response! :cheesy: ill test it tomrrow its kidna late now so if any problems come up ill give u a buzz
thanks a lot,
Max Mumford.
and thanks for the fast response! :cheesy: ill test it tomrrow its kidna late now so if any problems come up ill give u a buzz
thanks a lot,Max Mumford.
Ill solve somebody's thread someday! xD
Hi, I have just tested it and there is one error. im not entirely sure what it is so go here to see the script in action.
http://grafax.co.uk/switch/
Below is the script for the page.
http://grafax.co.uk/switch/
Below is the script for the page.
HTML and CSS Syntax (Toggle Plain Text)
<%@ LANGUAGE="JAVASCRIPT" var style = new String(Request.Cookies('style')); if(style==null || style=='undefined'){ style = new String(Request.Forms('style')); if(style==null || style=='undefined'){ style="default"; }else{ Response.Cookies('style') = style; } } %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a rel="nofollow" class="t" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <html xmlns="<a rel="nofollow" class="t" href="http://www.w3.org/1999/xhtml" target="_blank"> http://www.w3.org/1999/xhtml</a> "> <head> <link rel="stylesheet" type="text/css" href="/styles/style_<%Response.write(style)%>.css"/> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <select name="style" id="style"> <option value="styles.css" selected="selected">1</option> <option value="styles2.css">2</option> </select> </form> </body> </html>
Last edited by MaxMumford; Jan 26th, 2007 at 4:30 am. Reason: style sheet attatch not in head
Ill solve somebody's thread someday! xD
Ah; sorry. These two blocks shouldn't be combined:
You'll probably hit more errors now ^_-
HTML and CSS Syntax (Toggle Plain Text)
<%@ LANGUAGE="JAVASCRIPT" %> <% var style = new String(Request.Cookies('style')); if(style==null || style=='undefined'){ style = new String(Request.Forms('style')); if(style==null || style=='undefined'){ style="default"; }else{ Response.Cookies('style') = style; } } %>
You'll probably hit more errors now ^_-
Plato forgot the nullahedron..
The whole problem is that they won't keep things compatible.
We HAD a system where most web code was compatible. But then the elitists pounced, and decided that web code had to be more "elegant." Now we have a bifurcation between the newest browsers and the old ones.
There should be either a criminal penalty for introducing incompatibilities into a system that already works, or the person who introduced the incompatiblity should be forced to pay for the upgrade for everyone in the world.
We HAD a system where most web code was compatible. But then the elitists pounced, and decided that web code had to be more "elegant." Now we have a bifurcation between the newest browsers and the old ones.
There should be either a criminal penalty for introducing incompatibilities into a system that already works, or the person who introduced the incompatiblity should be forced to pay for the upgrade for everyone in the world.
Last edited by MidiMagic; Jan 26th, 2007 at 11:37 am.
Daylight-saving time uses more gasoline
HTML and CSS Syntax (Toggle Plain Text)
The whole problem is that they won't keep things compatible. We HAD a system where most web code was compatible. But then the elitists pounced, and decided that web code had to be more "elegant." Now we have a bifurcation between the newest browsers and the old ones. There should be either a criminal penalty for introducing incompatibilities into a system that already works, or the person who introduced the incompatiblity should be forced to pay for the upgrade for everyone in the world.
Has that got absolutely anything to do with this post, or did you intend it (the reply) to go elsewhere?
But anyway, assuming this is meant here:
ASP code will always be self-compatible because it doesn't matter how old a version of ASP you have on your server. ASP spits out HTML; and it can be as up-to-date or back-in-time as you (as the developer) so choses, If you update your ASP version, you only affect yourself.
Plato forgot the nullahedron..
Still not working :/ i have one stylesheet called styles.css which should be the default style sheet, i have another called styles2.css which is an alternate one. Is the code ok for that? Max
(new code..)
do i need anything in the form action section? at the moment i have a submit button and thats all..
(new code..)
HTML and CSS Syntax (Toggle Plain Text)
<%@ LANGUAGE="JAVASCRIPT" %> <% var style = new String(Request.Cookies('style')); if(style==null || style=='undefined'){ style = new String(Request.Forms('style')); if(style==null || style=='undefined'){ style="default"; }else{ Response.Cookies('style') = style; } } %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a rel="nofollow" class="t" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <html xmlns="<a rel="nofollow" class="t" href="http://www.w3.org/1999/xhtml" target="_blank"> http://www.w3.org/1999/xhtml</a> "> <head> <link rel="stylesheet" type="text/css" href="/styles/style_<%Response.write(style)%>.css"/> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> <select name="style" id="style"> <option value="styles.css" selected="selected">1</option> <option value="styles2.css">2</option> </select> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> <p> </p> <h1>test heading1 set only in style.css (origional style) </h1> </body> </html>
do i need anything in the form action section? at the moment i have a submit button and thats all..
Last edited by MaxMumford; Jan 26th, 2007 at 5:44 pm.
Ill solve somebody's thread someday! xD
HTML and CSS Syntax (Toggle Plain Text)
href="/styles/style_<%Response.write(style)%>.css"
This bit means it will be looking in the /styles/ folder for a file called style_[X].css, where [X] is the value submitted in the field named 'style' from the form/cookie.
I think there's a problem with the null-string checking aswell; in the two places where it says style=='undefined' try: style==''; so:
if(style==null || style==''){ style = new String(Request.Forms('style')); if(style==null || style==''){ style="default"; }else{ Response.Cookies('style') = style; } }
Plato forgot the nullahedron..
current code:
2 style sheets and page:
page: http://grafax.co.uk/switch/
style1: http://grafax.co.uk/switch/style_1.css
style2: http://grafax.co.uk/switch/style_2.css
somthing is still going wrong but im not sure. i understand a little of the asp code but not much.
Thanks for all your help by the way!
HTML and CSS Syntax (Toggle Plain Text)
<%@ LANGUAGE="JAVASCRIPT" %> <% var style = new String(Request.Cookies('style')); if(style==null || style==''){ style = new String(Request.Form('style')); if(style==null || style==''){ style="default"; }else{ Response.Cookies('style') = style; } } %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a rel="nofollow" class="t" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"> <html xmlns="<a rel="nofollow" class="t" href="http://www.w3.org/1999/xhtml" target="_blank"> http://www.w3.org/1999/xhtml</a> "> <head> <link rel="stylesheet" type="text/css" href="style_<%Response.write(style)%>.css"/> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> <select name="style" id="style"> <option value="1" selected="selected">1</option> <option value="2">2</option> </select> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> <p> </p> <h1>test heading1 set only in styles.css (origional style) </h1> </body> </html>
2 style sheets and page:
page: http://grafax.co.uk/switch/
style1: http://grafax.co.uk/switch/style_1.css
style2: http://grafax.co.uk/switch/style_2.css
somthing is still going wrong but im not sure. i understand a little of the asp code but not much.
Thanks for all your help by the way!
Ill solve somebody's thread someday! xD
![]() |
Other Threads in the HTML and CSS Forum
- Previous Thread: Problems with CSS in IE
- Next Thread: Html
| Thread Tools | Search this Thread |
appointments asp background backgroundcolor beta browser bug calendar cart cgi code codeinjection corporateidentity css design development displayimageinsteadofflash dreamweaver emailmarketing epilepsy explorer firefox flash form google griefers hackers hitcounter hover html ie7 ie8 iframe image images internet intranet iphone javascript jpeg layout macbook maps mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization pnginie6 positioning scroll seo shopping swf swf. textcolor timecolor titletags url urlseparatedwords visualization web webdevelopment webform website windows7






