PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old January 19th, 2004, 12:56 PM
gurdip gurdip is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 gurdip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Javascript within php causes an error

I'm having some trouble inserting the code for a free live chat program in php. I'm new to php.

The following code displays a little box with the heading Live Help and within that the chat code is to be added:

<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_HELP);

new infoBoxHeading($info_box_contents, false, false);

$info_box_contents = array();
$info_box_contents[] = array('align' => 'center', 'text' => BOX_HELP_TEXT . '<p>'. BOX_HELP_CHATCODE . '<p>');

new infoBox($info_box_contents);

?>


The chat code is as follows but the portion from onClick causes a problem in php so I can't include it:

<a href="http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690" target="_blank" onClick="this.newWindow = window.open('http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690&url=' + document.location, 'Chat', 'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=640,height=480'); this.newWindow.focus(); this.newWindow.opener = window;return false;"><img alt="Live chat by Boldchat" src="http://www.boldchat.com/bh.ci/1001294690" width="133" height="34" border="0"></a>


I have therefore defined BOX_HELP_CHATCODE as follows:

// information box text in includes/boxes/help.php
define('BOX_HEADING_HELP', 'Live Help');
define('BOX_HELP_TEXT', 'Got a question? Click here to ask our operator in realtime!');
define('BOX_HELP_CHATCODE', '<a href="http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690" target="_blank"><img alt="Live chat by Boldchat" src="http://www.boldchat.com/bh.ci/1001294690" width="133" height="34" border="0"></a>');


How can I add the full statement, ie from 'onClick' in the above so that it works as it should?

Thnx

Gurdip

Reply With Quote
  #2  
Old January 31st, 2004, 07:46 PM
pentapenguin pentapenguin is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 51 pentapenguin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 7 sec
Reputation Power: 6
Just quickly looked at this but "statusbar=0,men ubar=0" needs to be changed to "statusbar=0,menubar=0".
No space!
Let me know if this works.

Reply With Quote
  #3  
Old February 2nd, 2004, 07:39 AM
gurdip gurdip is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 gurdip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Not quite

Thanks for the response.
I suppose that would have caused a problem too (I hadn't noticed it in my code - so thnx) but the error message is still there. I saw an embedded code recently and in that the javascript code was shown within a single quotation mark. I tried the following but that wasn't it either:

define('BOX_HELP_CHATCODE', '<a href="http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690" target="_blank" 'onClick="this.newWindow = window.open('http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690&url=' + document.location, 'Chat', 'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=640,height=480'); this.newWindow.focus(); this.newWindow.opener = window;return false;"'><img alt="Live chat by Boldchat" src="http://www.lashkaara.com/images/livechat.gif" width="110" height = 50 border="0"></a>');

I came across a post (see: URL) where Stumpy seems to indicate that php and javascript don't go together. Is this true?

Last edited by gurdip : February 2nd, 2004 at 07:43 AM. Reason: Additional note:

Reply With Quote
  #4  
Old February 2nd, 2004, 10:29 AM
bbodien bbodien is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 7 bbodien User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to bbodien
Quote:
Originally Posted by gurdip
I came across a post (see: http://forums.devarticles.com/showthread.php?t=6391) where Stumpy seems to indicate that php and javascript don't go together. Is this true?


It's quite easy to combine them and end up with a mess of insecureness, but they can be used together to good effect.

Reply With Quote
  #5  
Old February 12th, 2004, 01:57 PM
catfrog catfrog is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 catfrog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question javascript, php, and quotation marks

maybe a similar issue

I am trying to incorporate a clientside javascript confirm/open window element. the problem is that our php version does not allow " and '

if i include quotation marks (which I have to for thi script), then the server will automatically add escape \ in front of the quote mark. the script won't work.

here is the script:

<script language = "JavaScript">

function loadLocation (myurl)
{ input = confirm("This link will open a new browser window. ATHENSi.com is not responsible for the link's content. Click cancel if you don't want to open this link","");
if (input != "")
{ window.open(myurl, "", ""); }
else
{ } }
</script>
<a href = javascript:loadLocation("http://athensi.com") >ATHENSi.com</a>

Reply With Quote
  #6  
Old February 12th, 2004, 04:52 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
I don't see any PHP in your post...
but perhaps you could try:
<a href="javascript:loadLocation('http://athensi.com');">

i don't understand why you have java_script_:

Reply With Quote
  #7  
Old February 12th, 2004, 05:39 PM
catfrog catfrog is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 catfrog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
I don't see any PHP in your post...
but perhaps you could try:
<a href="javascript:loadLocation('http://athensi.com');">

i don't understand why you have java_script_:


thanks...
i don't understand the undersscore, either, it is not in the original code and i am not sure how I managed to get them in when i copied things over here.

anyway, no, single quotes don't solve the issue. it won't work, and after saving the document in the database, the system adds backslashes there, too.

Reply With Quote
  #8  
Old February 12th, 2004, 10:09 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Hey, wait a second... underscores are in my post too... i know i took them out!

What is it about the single quotes that are causing problems?
and what's being saved to the database?
perhaps there's a bigger problem here...
exactly what error are you getting?

This is here for testing: <a href="javascript:loadLocation('http://athensi.com');">

*edit* something strange with the server i assume *edit*

Reply With Quote
  #9  
Old February 13th, 2004, 01:02 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
I'm thinking this forum puts in the underscores so that the Javascript isn't executed by the browser... it's a little off putting.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #10  
Old February 13th, 2004, 02:21 AM
Spongy's Avatar
Spongy Spongy is offline
Alternately High
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Hilversum, Netherlands
Posts: 223 Spongy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 56 m 41 sec
Reputation Power: 5
Send a message via MSN to Spongy
Quote:
Originally Posted by gurdip
define('BOX_HELP_CHATCODE', '<a href="http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690" target="_blank" 'onClick="this.newWindow = window.open('http://chat.boldchat.com/chat/visitor.jsp?cdid=1001294690&url=' + document.location, 'Chat', 'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=640,height=480'); this.newWindow.focus(); this.newWindow.opener = window;return false;"'><img alt="Live chat by Boldchat" src="http://www.lashkaara.com/images/livechat.gif" width="110" height = 50 border="0"></a>');

It is not so hard to see where it is going wrong. I'm no JS-guru but you start with single quotes and in the middle of your code you have them again!
Maybe it will work if you change all of the quotes?

Reply With Quote
  #11  
Old February 13th, 2004, 03:00 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Quote:
Originally Posted by bbodien
It's quite easy to combine them and end up with a mess of insecureness, but they can be used together to good effect.


Sorry - I probably should have explained myself more clearly.
Yes - you can combine your JS and PHP, but the two can't talk/interact with each other. Once the PHP is compiled on the server, they are completely separate. Only the HTML and JS is sent to the browser. The PHP is only executed on the server, and therefore is not realated to JS. For some reason, a lot of people confuse the two.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Javascript within php causes an error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway