Forum Moderators: open

Message Too Old, No Replies

variable confusion

         

efficacious

2:13 am on Sep 23, 2007 (gmt 0)

10+ Year Member



Hello all... total noob here..

I'm trying to write some js for my website...
basically what i want to do is

I have a menu setup which each link will be a graphic...
when a users click the link i want to write a function that "onlick" changes a variable to write the correct pages title in the specific place... here is my code so far:

___.jS SIDE____

//** START VARIABLES **//

var Ptitle = "DEFAULT"

//** MAIN FUNCTIONS **//

//** MENU **//

function PtitleChange1()
{
Ptitle="NEWPAGE1"
}

function displayTitle()

{
document.write(Ptitle);
}

____html side___

<script>displayTitle()</script>

<a name="cliker" href="#" onclick="PtitleChange1()">CLICK TEST</a>

i can't for the life of me figure this out... and nowhere i've found explains how to properly work with variables just tells you how u can... no explanation on how to actually do it..

I am very new to js but I do understand most of the language

plz help thanx, efficacious

daveVk

2:35 am on Sep 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code should correctly change the global variable Ptitle to "NEWPAGE1" on clicking link, but thats all it does, it a procedural language not a functional one. The call to displayTitle is past history.

p.s. there are few missing semicolons.

Was that the question? Welcome to forum.

efficacious

2:41 am on Sep 23, 2007 (gmt 0)

10+ Year Member



yes thats what i'm trying to do... so how do i need to alter the code so that I can achieve that goal?

thanx, I need to join one i've been coding for awhile now with html,css and such and i'm trying to focus my attention more toward js and php now. trying to get myself more business oriented. rather then just making styles for phpbb

efficacious

3:01 am on Sep 23, 2007 (gmt 0)

10+ Year Member



ok i think i got it... if i do this:

___JS SIDE___

//** START VARIABLES **//

var Ptitle;

//** MAIN FUNCTIONS **//

//** MENU **//

function displayTitle()

{
document.write(Ptitle);
}

___HTMLSIDE____

//INSIDE EACH NEW PAGE

<script>Ptitle="FrontPage"</script>

that way anytime that page navigated to it gets switched...

daveVk

3:20 am on Sep 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function PtitleChange1()
{
Ptitle="NEWPAGE1";
displayTitle();
}

Should do the trick. In this simple example, the variable could be factored out, say displayTitle( "NEWPAGE1" ). The use of variables make sense if there are multiple page parts you wish to change via links and displayTitle becomes displayPage.

efficacious

3:34 am on Sep 23, 2007 (gmt 0)

10+ Year Member



thanx a million for the help dave...
i got it working...

i have my pages setup using php like this:

__HEADER.php___

__Menu.php__

__index.php__

__footer.php__

i needed the title of the page displayed in the header.php

my index.php looks like this:

<script>
Ptitle="HOMEPAGE";
</script

<?php include("header.php");?>

<table height="468px" align="center" id="IndexPageMain">
<tr>
<td>
BLAH
</td>
</tr>
</table>

<?php include("footer.php");?>