Click to See Complete Forum and Search --> : Javascript Code Help (If else with HTMl output)


danprhayes
04-22-2003, 10:51 AM
Hi

I am retrieving the value of a cookie and want to display a different html page depending on the value of that cookie....

var checkvalue = get_Cookie('navigation')
if (checkvalue == "advanced")
document.write("<p>you selected advanced.</p>")

else if (checkvalue == "simple")
document.write("<P>you selected simple.</p>")

This works but I want all the html tags ie <HTML><BODY> etc not just a one liner so I can contruct either of two pages from this one page of code

NB: I dont want the code to direct to a different HTML page since I want this file to be an include page.

Hope that makes sense.

Daniel

Jona
04-22-2003, 10:58 AM
Use SSI <!--#include="advanced.html"--> instead of <p>you selected advanced</p> and <!--#include="simple.html"--> instead of <p>you selected simple</p>.

BTW, you will need SSIs to do this, if you don't have them.... I don't know what to tell you. :D

havik
04-22-2003, 11:03 AM
Well, I'd suggest redirection based on the value of the cookie, but since that's not an option you'd need to build the page with javascript based on checkvalue.

if(checkvalue=="advanced")
build advanced page here

else if(checkvalue=="simple")
build simple page here

In cases where the code is exactly the same, then there's no need to document.write it twice.

example:

document.write('<html><head>'); // not repeated

if(checkvalue=="advanced")
document.write('<title>Advanced Section</title>');
else
document.write('<title>Simple Section</title>');
document.write('</head>'); // not repeated

Havik