Current location: Hot Scripts Forums » Programming Languages » PHP » Mouseover with Single PHP page

Mouseover with Single PHP page

Reply
  #1  
Old 09-14-04, 10:56 PM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Mouseover with Single PHP page

I need a little help if someone has the time....

I am using a single PHP template and loading the content through the address bar. EX: www.mysite.com/frameset.php?content=home would obviously display the home page.

Prior to using PHP I use to create multiple pages and the mouseovers were simple because they were all self contained in each file, so to get the effect I'm trying to do now is becoming near impossible with my limited PHP knowledge.

I am using a simple two image mouseover. I would like for the image corosponding to the page that is currently loaded to stay the mouseover image and the others to be the non-moused images.

Currently it's a mixture of java and php getting it all done, but I just keep seem to get the current page image to display the way I'm looking for it to.

The following is the code I'm using, more input to follow...

This is in the HEAD
Code:
  <SCRIPT LANGUAGE="JavaScript">
	<!-- Pre-Download of images

	image1 = new Image();
	image1.src = "rj_link_home.jpg";

	image2 = new Image();
	image2.src = "rj_link_homems.jpg";

	image7 = new Image();
	image7.src = "rj_link_faq.jpg";

	image8 = new Image();
	image8.src = "rj_link_faqms.jpg";

	image11 = new Image();
	image11.src = "rj_link_about.jpg";

	image12 = new Image();
	image12.src = "rj_link_aboutms.jpg";

	// End -->
  </SCRIPT>
  <SCRIPT language="JavaScript">

	<!-- Begin Mouse Over
	function move_in(img_name,img_src) {
	document[img_name].src=img_src;
	}

	function move_out(img_name,img_src) {
	document[img_name].src=img_src;
	}
	// End -->
  </SCRIPT>
That preloads the images and sets up the function for the mouseover.
Then the links look like this.

Code:
<A onmouseover="move_in('home','rj_link_home.jpg')" onmouseout="move_out('home','rj_link_homems.jpg')"
		      HREF="./frameset.php?content=home"><IMG NAME="home" ALT="Home Page" SRC="rj_link_home.jpg"
		      WIDTH="93" HEIGHT="31" BORDER="0"></A>
Ok, so all that is java and not PHP. I'll get to that shortly.

This has worked many years for multi-html pages, however, using PHP to load the content instead of having separate HTML pages now makes it so either I don't use a mouseover or all links have to be mouseover. In this code, I would like it that if $content=home then this image will be rj_link_home.jpg else image is rj_link_homems.jpg and will change to the other onmouseover.

I wouldn't mind converting to completely to PHP, but alas knowing what you want it to do and being able to format the code to do has been my downfall for many years.

There is one more problem with this code that you should be aware of. As of WinXP Service Pack 2 which just came out, there is even more security in MSIE that now prevents this code from functioning unless the user gives it permission to function. By default it will not function until the user clicks on this new warning bar that appears at the top of the page. It's quickly becoming a pain. I was hoping to be able to convert this to PHP with code that MSIE will not yell about. I'm not sure how many people here jumped on the next service pack, but you know many end users will be running it shortly.

Anyway, if anyone cares to lend a little hand with this it would be greatly appreciated.
Reply With Quote
  #2  
Old 09-14-04, 11:00 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Why not just echo the js with php with the varialbes inside....
Reply With Quote
  #3  
Old 09-16-04, 01:21 AM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Work around for now.

Quote:
Originally Posted by Eclipse
Why not just echo the js with php with the varialbes inside....
I'm sorry. I said allot and am not sure which issue you were thinking this would help with...

In the meantime, I came up with something that should work for the short term. Something where I can get this site up sooner than later, than I can refine it a bit more...

Please look at this code. I know I'm missing something small in it. I believe it's the $content == home, I think because content is actually a string and not a value that I'm having an issue. Could you take a look and help me out a little?

Code:
<?PHP

if ($content == home) {
	echo '<IMG SRC="homelink_onpage.jpg" BORDER="0" WIDTH="93" HEIGHT="31">';
} else {
	echo '<A onmouseover="move_in('home','homelink_mouse.jpg')" onmouseout="move_out('home','homelink_nomouse.jpg')" HREF="./frameset.php?content=home">';
	echo '<IMG NAME="home" ALT="Home Page" SRC="homelink_nomouse.jpg" WIDTH="93" HEIGHT="31" BORDER="0"></A>'
}
?>
I hope that came through correclty, it wraps when writing it. Guess I'll see.

Thanks for the help,
RJ
Reply With Quote
  #4  
Old 09-16-04, 01:59 AM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, this should work, I think, but it's too late for me to try it now. I FINALLY found an example that showed what I was looking for. Dang php.net didn't show it in all of thier if statement examples. grrrr. Moving on.

One other thing. I've seen in other languages where you have to end the if statement. It didn't appear that you had to end it with and endif on php.net, but I did see some examples where an endif was used. What is required?

Will this work? I'll try it in the morning to see.

PHP Code:
<?PHP

if ($content == "home") {
    echo 
'<IMG SRC="homelink_onpage.jpg" BORDER="0" WIDTH="93" HEIGHT="31">';
} else {
    echo 
'<A onmouseover="move_in('home','homelink_mouse.jpg')" onmouseout="move_out('home','homelink_nomouse.jpg')" HREF="./frameset.php?content=home">';
    echo 
'<IMG NAME="home" ALT="Home Page" SRC="homelink_nomouse.jpg" WIDTH="93" HEIGHT="31" BORDER="0"></A>'
}
?>
Reply With Quote
  #5  
Old 09-16-04, 11:23 AM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
It doesn't work either. I get an unexpected T_String on line 10 which is the first echo after the else. grrrrr.

I've been over and over that and don't understand why it won't work. I think it has something to do with the other ' used in the <A onmouseover....

Any ideas would be helpful.

Thanks,
RJ
Reply With Quote
  #6  
Old 09-16-04, 11:42 AM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, I'm not sure if this is better or not. Any feedback would be appreciated, but I found an alternative syntax for if statements on php.net. The following works for my purposes, but MSIE under XP SP2 and won't display properly without users permissions. I'll have to figure out if that is the preload script or the mouseover script and go from there.

PHP Code:
<?PHP if($content == "home"): ?>

     <IMG SRC="rj_link_home_onpage.jpg" BORDER="0" WIDTH="93" HEIGHT="31">

<?PHP else: ?>

     <A onmouseover="move_in('home','rj_link_home_mouseon.jpg')" onmouseout="move_out('home','rj_link_home_nomouse.jpg')" HREF="./frameset.php?content=home">
     <IMG NAME="home" ALT="Home Page" SRC="rj_link_home_nomouse.jpg" WIDTH="93" HEIGHT="31" BORDER="0"></A>

<?PHP endif; ?>
Reply With Quote
  #7  
Old 09-16-04, 06:05 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
Well since no one else in this huge community of ours will help you i'll take a stab at it:
PHP Code:
if ($content == "home") { 
    echo 
'<IMG SRC=\"homelink_onpage.jpg\" BORDER=\"0\" WIDTH=\"93\" HEIGHT=\"31\">'
} else { 
    echo 
'<A onmouseover=\"move_in(\'home\',\'homelink_mouse.jpg\')" onmouseout=\"move_out(\'home\',\'homelink_nomouse.jpg\')\" HREF=\"./frameset.php?content=home\">'
    echo 
'<IMG NAME=\"home\" ALT=\"Home Page\" SRC=\"homelink_nomouse.jpg\" WIDTH=\"93\" HEIGHT=\"31\" BORDER=\"0\"></A>' 

That should work jsut as a note you need a "/" before certine carecters in php other wise it will think that you are ending the string so to write a ' or " to an html via php you need to put a / before it or php with interperate it as you are ending the string followed by bunches of junk that it doesn't understand. Well hope that helps.
Also as a side note you can start php with a "<?" and close with a "?>" instead of <?php to open and ?> to close. In addition if you have acess to php.ini you can set <% to open and %> to close or anything you want really; I use'd <¥ to open and ¥> to close but now i just use <? and ?>

Last edited by Eclipse; 09-16-04 at 06:09 PM. Reason: cause BB code sucks....
Reply With Quote
  #8  
Old 09-16-04, 06:15 PM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Eclipse
That should work jsut as a note you need a "/" before certine carecters in php other wise it will think that you are ending the string so to write a ' or " to an html via php you need to put a / before it or php with interperate it as you are ending the string followed by bunches of junk that it doesn't understand. Well hope that helps.
Well shucks! Thanks, that is some helpful information. I guess for ppl who have been programming PHP for ages it's second nature. I'll get there, but it's obviously not my forte.

In any case, thanks, that worked, I've got one last issue I'm fighting and this project will be done. I'll post that as a separate message.

Thanks again,
RJ
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i make php open another web page? wonderland PHP 6 09-23-08 07:55 PM
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Help! With setting up a basic PHP Forum page on the website. A-A PHP 0 05-05-04 09:15 AM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 01:11 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 11:56 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)