Probably simple...

J

Jim

Hi,

I'm new to HTML, JavaScript and all that so can anyone
tell me the correct Javascript syntax to achieve the
following.....

If condition true then
display page1.htm
else
display page2.htm
end if

Appreciate your help!
 
J

jon spivey

Hi Jim

2 methods - the shorthand
<script type="text/javascript">
location.href=(somevar=='somevalue')?'Page1.htm':'Page2.htm';
</script>
or the longhand
<script type="text/javascript">
if(somevar=='somevalue'){
location.href='Page1.htm';
else{
location.href='Page2.htm';
}
</script>

Don't forget that in javascript to test if a value is equal to something
else we use 2 equal signs == eg
if(yourname=='Jim') if(yourname='Jim') would always evaluate to true
whatever the value of yourname - this catches nearly everyone out at some
time
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top