Go Back   Gaming Gutter > Non-Gaming > Programming


Programming - All general programming discussion in here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post Looking to buy 1-2...
Today 06:33 AM
Last post by Fewmitz again
Today 07:14 AM
7 Replies, 8 Views
Go to first new post Im Selling Roughly 76m...
Today 03:20 AM
by venture
Last post by ASHTEHCOMMIE
Today 07:12 AM
27 Replies, 28 Views
Go to first new post [PC]Account
Today 07:11 AM
by Kaze
Last post by Kaze
Today 07:11 AM
0 Replies, 1 Views
Go to first new post FIFA 08 fans in here!
07-22-2008 06:27 AM
Last post by venture
Today 07:11 AM
1 Replies, 2 Views
Go to first new post Sex before Marriage?
08-18-2008 04:15 AM
by mika
Last post by terinuptrash
Today 07:10 AM
42 Replies, 43 Views
Reply
 
LinkBack Thread Tools Display Modes

 using javascript variables in php
Old 03-27-2008, 12:02 PM   #1 (permalink)
Underground
 
revolution's Avatar
 
revolution is offline
Join Date: Aug 2007
Location: Hiram, Georgia
Age: 19
Posts: 557
iTrader: 2 / 100%
revolution Is Recognizable
Rep Power: 4
using javascript variables in php

Long story short, I need a php if else statement to recognize a change to an image due to javascript.

I'll post a condensed version of the code:

Code:
<html>
<head>
<script type="text/javascript">
function mouseOver1()
{
document.rating1.src ="blog/img/star.png";
}
function mouseOut1()
{
document.rating1.src ="blog/img/nostar.png";
}
function onClick1()
{
document.rating.src ="blog/img/1.png";
document.rating1.src ="blog/img/star.png";
}
</script>
</head>
<body bgcolor=ffffff>
<center>
<img border="0" src="blog/img/nostar.png" name="rating1" value="One" id="rating1" width="16" height="16" onmouseover="mouseOver1()" onmouseout="mouseOut1()" onclick="onClick1()" />
<br /><br />
<img border="0" src="blog/img/0.png" name="rating" value="Zero" id="rating">
</center>
</body>
</html>
Obviously the current onClick function is pointless thanks to the mouseOut function, but that's not my concern. I want something similar to the following, but a working version:

Code:
<?
if (document.rating.src=="blog/img/1.png")
echo "1 Star";
elseif (document.rating.src=="blog/img/2.png")
echo "2 Stars";
elseif (document.rating.src=="blog/img/3.png")
echo "3 Stars";
elseif (document.rating.src=="blog/img/4.png")
echo "4 Stars";
elseif (document.rating.src=="blog/img/5.png")
echo "5 Stars";
?>
It's a rating from 1 to 5 stars, but since I just posted a condensed version, I only really need a condensed solution and I can apply it from there. Basically, when you click the 1st star, image 1.png replaces image 0.png, when you click the 2nd star, image 2.png replaces image 0.png and so on up to the 5th star image. The problem is the php doesn't recognize the change to the rating src to echo anything based on the change.

Would I need to amend the php coding or the javascript? If so, what?
__________________
Trades Completed:
Yummy, Kismet, Konekokoi, xRuinationx




  Reply With Quote

 
Old 03-29-2008, 05:25 PM   #2 (permalink)
Full Member
 
unlimitedorb is offline
Join Date: Feb 2008
Posts: 25
iTrader: 0 / 0%
unlimitedorb Is gaining popularity
Rep Power: 2
I don't fully understand what you are doing, but from the code you pasted above you can merge the PHP with the javascript if all you want to do is print whether it's 1 star, 2 stars, etc.

Create a <div></div> where you want the text to be placed. Next, give the <div> an id:
Code:
<div id = "starText"></div>
Now add in this snippet to your javascript:
Code:
document.rating1.src ="blog/img/nostar.png";
window.document.getElementById("starText").innerHTML = "One Star";
This grabs the div with the ID of "starText" and changes the HTML inside the tag on the fly.
  Reply With Quote

 
Old 03-30-2008, 05:17 PM   #3 (permalink)
Underground
 
revolution's Avatar
 
revolution is offline
Join Date: Aug 2007
Location: Hiram, Georgia
Age: 19
Posts: 557
iTrader: 2 / 100%
revolution Is Recognizable
Rep Power: 4
Worked perfect. Applied it to the onClick instead of mouseOut like you had. Now that that's fixed, I have another question. Making another topic to avoid confusion.

One more question about that though. I still want it to be able to be used in php. Is there a way I can store that "One Star" as a variable in php if the 1st star is clicked or store "Two Stars" if the 2nd star is clicked, etc?
__________________
Trades Completed:
Yummy, Kismet, Konekokoi, xRuinationx




  Reply With Quote

 
Old 03-30-2008, 07:54 PM   #4 (permalink)
Full Member
 
unlimitedorb is offline
Join Date: Feb 2008
Posts: 25
iTrader: 0 / 0%
unlimitedorb Is gaining popularity
Rep Power: 2
You could, but you would have to store that information somehow. Some ways you could do this are: using a database such as Mysql to store the information, or using a flat file to store the information. Maybe PHP supports object serialization? I forgot it's been awhile since I've been on the web development scene =(
  Reply With Quote

 
Old 03-31-2008, 02:08 PM   #5 (permalink)
Junior Member
 
ricky92 is offline
Join Date: Mar 2008
Posts: 1
iTrader: 0 / 0%
ricky92 Is gaining popularity
Rep Power: 0
Using Javascript you could just use a cookie. However, this is not the best solution, and I would suggest to send a request to a page using AJAX to store the data in a database...
  Reply With Quote

 
Old 03-31-2008, 11:03 PM   #6 (permalink)
Underground
 
revolution's Avatar
 
revolution is offline
Join Date: Aug 2007
Location: Hiram, Georgia
Age: 19
Posts: 557
iTrader: 2 / 100%
revolution Is Recognizable
Rep Power: 4
I'm looking to just store it as a variable actually. Like in a FLP, they enter their password and you can use $password (if that's what you declared it to be) throughout your site to display or use their password. I'd like to do something similar so that say when two stars are clicked to display "Two Stars" a variable in php such as $Stars would be "Two Stars" so I could just do echo $Stars; to display the value.
__________________
Trades Completed:
Yummy, Kismet, Konekokoi, xRuinationx




  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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 07:16 AM.


vBulletin skin developed by: eXtremepixels
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.26436496 seconds (100.00% PHP - 0% MySQL) with 19 queries