|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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: |
|
#4
|
|||
|
|||
|
Quote:
It's quite easy to combine them and end up with a mess of insecureness, but they can be used together to good effect. |
|
#5
|
|||
|
|||
|
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> |
|
#6
|
||||
|
||||
|
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_: |
|
#7
|
|||
|
|||
|
Quote:
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. |
|
#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* |
|
#9
|
||||
|
||||
|
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.
|
|
#10
|
||||
|
||||
|
Quote:
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? |
|
#11
|
||||
|
||||
|
Quote:
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Javascript within php causes an error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|