Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Closed Thread
Javascipt "IF" statement to include PHP code
Old 09-01-2004, 10:19 AM Javascipt "IF" statement to include PHP code
Skilled Talker

Posts: 79
Trades: 0
Hello,

I'm trying to include a PHP piece of code, based on an IF statement.

Basically, I have a popup window on my side (which gives further information about specifics). This in only needed on one page, but the <head> is in a differnet file. Page titles are assigned using <?php echo $_GET["title"] ?>, with ?title=blah in the URL.

Therefore, I would like to use Javascript to include my peice of code if the page title equals a specific one.

Here is the page i'm working on http://www.alphalenzie.org.uk/talkti...=Talk%20Titles

Here is the piece of JS I put in the <head>:
Code:
<SCRIPT>
if(<?php echo $_GET["title"] ?>=Talk Titles){
   document.write("<SCRIPT>
<!-- PopUp Link JavaScript Code Provided By: http://www.DesignerWiz.com - Development Resource & JavaScript Public Archive Center -->
function popUp(page,PWidth,PHeight,id) {
 eval("designerwiz"+id+"=window.open('"+page+"','designerwiz1','toolbar=0,scrollbars=0,location=0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+"')")

}
</SCRIPT>")
}

else {}
</SCRIPT>
As you can see, this didn't work

i tried to get it to "write" the code there, but it was contained within a <script> tag alreadym and that probably screwed it up.

In conclusion, I'm trying to include a JS file, based on the fact that the page title is a specific name.

Second quesion: I will be making about 20 of these popups. This is a huge about of JS coding if each one is in the form:
Code:
<SCRIPT>
<!-- PopUp Link JavaScript Code Provided By: http://www.DesignerWiz.com - Development Resource & JavaScript Public Archive Center -->
function popUp(page,PWidth,PHeight,id) {
 eval("designerwiz"+id+"=window.open('"+page+"','designerwiz1','toolbar=0,scrollbars=0,location=0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+"')")

}
</SCRIPT>
Is there any way to add popup IDs to this line of code? IE, would ...
Code:
"+page+"','designerwiz1','designerwiz2','designerwiz3','toolbar=0,
...
work?


Thanks in advance for any suggestions on this matter.

Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
View Public Profile
 
 
Register now for full access!
Old 09-01-2004, 10:36 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
There is so much wrong, I don't know where to start

OK, this code;

HTML Code:
<SCRIPT>
if(<?php echo $_GET["title"] ?>=Talk Titles){
   document.write("<SCRIPT>
<!-- PopUp Link JavaScript Code Provided By: http://www.DesignerWiz.com - Development Resource & JavaScript Public Archive Center -->
function popUp(page,PWidth,PHeight,id) {
 eval("designerwiz"+id+"=window.open('"+page+"','designerwiz1','toolbar=0,scrollbars=0,location=  0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+"')")

}
</SCRIPT>")
}

else {}
</SCRIPT>
First of all, line #1 of your script;
- You have a single equals sign '='. You use a double '==' to compare
- your title needs to be in speach marks ("Talk Titles")


Your document.write code contains un-escaped speach marks; eval(" should be eval(\" (etc).

You should declare the script language;
<script language="Javascript">

To add ID's from a PHP script just do <?=$page_id ?> Where ever you want the vars, or to do it client side make a function;

HTML Code:
function popupWindow(szFile) {
     window.open(szFile);
.... etc
}
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
View Public Profile Visit webwoRRks's homepage!
 
Old 09-01-2004, 10:40 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
To include a specific file (server side evaluation) do something like this;

PHP Code:
<?php

$allTitles 
= array();
$allTitle["Talk Titles"] = "my_script1.js";
$allTitle["More Titles"] = "my_script2.js";

if(isset(
$allTitles[$_GET['title']])) { echo "<script language=\"Javascript\" src=\"".$allTitles[$_GET['title']]."\"></script>\n"; }

?>
Hope that explains things
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
View Public Profile Visit webwoRRks's homepage!
 
Old 09-01-2004, 11:15 AM
Skilled Talker

Posts: 79
Trades: 0
Hey

I like the second suggestion best, as I have more experience with PHP than JS.

I only need it to be included into the page if the page title is Talk Titles. Can I get rid of $allTitle["More Titles"] = "my_script2.js"; in this case?

If have not managed to get it working, but I will keep trying. Given that I only need it to be on this one page, can I simplify the IF statement so that it doesn't "GET" the variable?

Thanks for your help so far.

Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
View Public Profile
 
Old 09-01-2004, 11:34 AM
Skilled Talker

Posts: 79
Trades: 0
Hi

I have sorted it out now, thanks to your suggestion.

The code I used was:
Code:
<!-- choose to include popup -->
<?php
if ( $_GET["title"]  == "Talk Titles" ) {
include("further_info.js");
}
?>
<!-- end choose to include popup -->
Thanks for helping.

Hamish
__________________

Please login or register to view this content. Registration is FREE
secure and fully automated computer data backup for small and medium sized companies.


Please login or register to view this content. Registration is FREE
hamish is offline
View Public Profile
 
Old 09-02-2004, 06:00 AM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
no problem
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
View Public Profile Visit webwoRRks's homepage!
 
Closed Thread     « Reply to Javascipt "IF" statement to include PHP code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26853 seconds with 12 queries