To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-11-2006, 02:20 AM   #1
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
Using javascript variables in php

now before you assume that i'm a impatient/lazy newb, i'm a php newb, not a forum newb, i've used the search function, but the only match i found didn't explain it to a point where i could understand.

anyways, i'm in the middle of making my first custom php script and have hit a bit of a snag. i need a piece of data that's only ubtainable via js, but i need to know how use the variable produced in a php if/else statement:

Code:
var monitors = app.monitors.primary();
var res = monitors[0].rect;

<?php 
if( $res[2] < 1024 && res[3] < 768)
.....
?>

blue=php
red=javascript
can anyone help?

-Samo
Samo is offline   Reply With Quote
Old 03-11-2006, 02:26 AM   #2
bradgrafelman
Pna lbh ernq guvf?
 
Join Date: Jul 2004
Location: 40.566N -89.731W, ~469ft above sea level
Posts: 11,488
Well, first of all, I have to ask -

You realize that JS is client-side, and PHP is server-side, right? So anything you do in JS has to be transmitted back to the server before you can use it in a PHP script. This can be done through solutions such as AJAX, or simply reloading the page.
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)

Useful links: Debugging 101 || NJOE || (Sig image) || Rolla Engineered Solutions, LLC
bradgrafelman is offline   Reply With Quote
Old 03-11-2006, 02:41 AM   #3
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
hmmmmm, is there anyway to do it with out refreshing, like say, making the if statement javascript but the rest php?
Samo is offline   Reply With Quote
Old 03-11-2006, 02:48 AM   #4
bradgrafelman
Pna lbh ernq guvf?
 
Join Date: Jul 2004
Location: 40.566N -89.731W, ~469ft above sea level
Posts: 11,488
As I said, you'll need to look into methods that use Javascript to communicate with the server, such as AJAX. Otherwise, no. You're talking about two completely different ends of the connection here.
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)

Useful links: Debugging 101 || NJOE || (Sig image) || Rolla Engineered Solutions, LLC
bradgrafelman is offline   Reply With Quote
Old 03-11-2006, 03:11 AM   #5
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
ok, thx anyways

one last quuestion, can html be used in place of xml with AJAX?
Samo is offline   Reply With Quote
Old 03-11-2006, 03:15 AM   #6
FatalError
Senior Member
 
Join Date: Dec 2005
Location: Earth
Posts: 153
Quote:
Originally Posted by Samo
ok, thx anyways

one last quuestion, can html be used in place of xml with AJAX?
HTML isn't a scripting language, therefore it can't actually do anything, all HTML does is changes how the page looks...so no, it can't.

I found this tutorial very useful for learning AJAX.
__________________
Some useful tools:
Notepad++ | Firebug
FatalError is offline   Reply With Quote
Old 03-11-2006, 03:19 AM   #7
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
then does anyone know how i can make an if statement out of a javascript statement that will change the html, that's all i need, an if statement that will change the html of the page
Samo is offline   Reply With Quote
Old 03-11-2006, 03:35 AM   #8
bradgrafelman
Pna lbh ernq guvf?
 
Join Date: Jul 2004
Location: 40.566N -89.731W, ~469ft above sea level
Posts: 11,488
Depending on what you need to do, sure, I've used JS to alter the HTML of pages.

But now you start running into browser compatibility issues. The JS I originally made seemed to be compatible with IE only - not a good practice to code for.
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)

Useful links: Debugging 101 || NJOE || (Sig image) || Rolla Engineered Solutions, LLC
bradgrafelman is offline   Reply With Quote
Old 03-11-2006, 03:38 AM   #9
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
would it work in firefox if the code was just changing an image's dimension?
Samo is offline   Reply With Quote
Old 03-11-2006, 03:41 AM   #10
bradgrafelman
Pna lbh ernq guvf?
 
Join Date: Jul 2004
Location: 40.566N -89.731W, ~469ft above sea level
Posts: 11,488
Not sure. You'll have to give it a shot and see what happens.

Sorry I can't be of much help... my knowledge of JS is very limited. If I get time in the next few minutes, I can play around with FF and JS and see what I can come up with. If you're free right now though, you'll probably get results sooner by tinkering with it yourself.
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)

Useful links: Debugging 101 || NJOE || (Sig image) || Rolla Engineered Solutions, LLC
bradgrafelman is offline   Reply With Quote
Old 03-11-2006, 03:44 AM   #11
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
nah, i g2g2 bed, almost 3am but i'm free all day tommorrow, or uh, today i guess

i'll give it ago but i won't really be able to know if works unless i can test it on a computer with a res smaller than 800x600

thx though
Samo is offline   Reply With Quote
Old 03-11-2006, 04:48 AM   #12
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,122
Since this has ended up being about Javascript, I'm moving it to a different forum.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 03-11-2006, 04:50 AM   #13
bradgrafelman
Pna lbh ernq guvf?
 
Join Date: Jul 2004
Location: 40.566N -89.731W, ~469ft above sea level
Posts: 11,488
'Morning weed!

I'm afraid that I'm going to have to give up on this one as well... sorry Samo. If you need help with the PHP side of it, feel free to re-post a PHP question!
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)

Useful links: Debugging 101 || NJOE || (Sig image) || Rolla Engineered Solutions, LLC
bradgrafelman is offline   Reply With Quote
Old 03-11-2006, 03:23 PM   #14
Samo
The Graphics Kid
 
Join Date: Mar 2006
Posts: 21
k, thx for...........saving hours of frustration

i'll let ya know if works
Samo is offline   Reply With Quote
Reply

Bookmarks


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

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
Forum Jump


All times are GMT -4. The time now is 03:18 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.