| Author |
Message |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Wed May 07, 2003 8:13 am |
  |
This question has been asked and answered more times than I can recall. There is a PHP built in way to do this that is very simple and fool-proof.
First I will show you an example and then explain it.
| Code: |
$someVarName = <<<_JSCODE_
<script>alert('Hello World');</script>
_JSCODE_;
echo $someVarName;
|
That's it! You simply insert your JavaScript code as you use it in your HTML document and drop it in. You do not have to escape any quotes or anything special. If it works in native HTML, it should work here.
Now for a caveat. You can use PHP variables in the code WITHOUT using the <? ?> tags. Here would be an example of that.
| Code: |
$messageText = 'Hello World';
$someVarName = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;
echo $someVarName;
|
Now, if you were using this in a block, you need to assign all content to the $content variable. You could do this in a separate line of code, like this
| Code: |
$messageText = 'Hello World';
$someVarName = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;
$content = $someVarName;
|
or just assign the block to $content instead of $someVarName like this.
| Code: |
$messageText = 'Hello World';
$content = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;
|
There is only 1 very important syntactical rule for usage. In my example _JSCODE_ is analogous to a BLOCK TAG. These tags can be named whatever you want, as can the $someVarName. However, the ending block tag MUST be left aligned AND there can be no character EXCEPT a carriage return after either of the block tags. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
ferrari4ever
Corporal


Joined: May 30, 2003
Posts: 63
Location: The Netherlands
|
Posted:
Mon Jun 02, 2003 6:20 am |
  |
thanx... |
Last edited by ferrari4ever on Mon Jun 02, 2003 8:27 am; edited 1 time in total |
|
   |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Mon Jun 02, 2003 6:27 am |
  |
|
    |
 |
ferrari4ever
Corporal


Joined: May 30, 2003
Posts: 63
Location: The Netherlands
|
Posted:
Mon Jun 02, 2003 7:04 am |
  |
| Raven wrote: |
| Not again. There are enough examples given. Search the forums! |
Great thanks for your help...  |
|
|
   |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Mon Jun 02, 2003 7:07 am |
  |
Feed a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
I have provide examples for all cases. Even as recently as yesterday that answers your EXACT question. I have provided you your answer already. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
chatserv
General


Joined: Jan 12, 2003
Posts: 3128
Location: Puerto Rico
|
Posted:
Mon Jun 02, 2003 7:20 am |
  |
I just had to grab that line, refrain from taking this to court for now as my lawyer went on a strike. |
_________________ Feed a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
ScriptHeaven | NukeResources |
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Mon Jun 02, 2003 7:31 am |
  |
Let me know when it's convenient
Author unknown on the quote. Don't you just love it when you supply the answers and still get blasted? I want a raise! I deserve at least a case of Pepsi a month. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
chatserv
General


Joined: Jan 12, 2003
Posts: 3128
Location: Puerto Rico
|
Posted:
Mon Jun 02, 2003 7:35 am |
  |
Something in that general direction may be coming up soon, now, you do have a point on what transpired in this post, not the first time i see it though, surely won't be the last. |
_________________ Feed a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
ScriptHeaven | NukeResources |
|
    |
 |
chris-au
Elite Nuker


Joined: Jan 31, 2003
Posts: 717
|
Posted:
Thu Jun 05, 2003 5:51 pm |
  |
Only in a perfect world, where everybody is fortunately enough to live near water where fish can survive in this wonderfull polluted world, could the following be believable:
| Quote: |
| Feed a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime |
|
|
|
    |
 |
Densmore
Nuke Cadet


Joined: Jun 23, 2003
Posts: 6
|
Posted:
Mon Jun 23, 2003 3:36 pm |
  |
I just wanted to stop and take a moment to say THANK YOU for all the work you guys put in on this stuff! It takes time, effort, comittment, brain power and a ton of patience to moderate forums of this nature and I thank you all now for all of the help I am about to receive!  |
|
|
   |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Mon Jun 23, 2003 4:01 pm |
  |
Actually 2.34875 tons, but whose counting
Thanks from all the staff at NC! |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Rafael
Corporal


Joined: May 24, 2003
Posts: 71
|
Posted:
Mon Jun 30, 2003 9:15 pm |
  |
We just may have to create a separate forum where we can lavish praise and kudos on the nukecops staff! Great job guys! Your help may often go uncommented but definitely not unappreciated.  |
|
|
   |
 |
Kenshin_The_Battousai
Nuke Soldier


Joined: Jul 25, 2003
Posts: 21
Location: Columbus, Ohio
|
Posted:
Tue Jul 29, 2003 3:29 pm |
  |
will the work for the messages too for teh home page |
|
|
        |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Tue Jul 29, 2003 4:32 pm |
  |
| Kenshin_The_Battousai wrote: |
| will the work for the messages too for teh home page |
Please restate you question. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
leezard
Nuke Soldier


Joined: Aug 04, 2003
Posts: 16
|
Posted:
Mon Aug 04, 2003 2:28 pm |
  |
Just had to register and thank Raven, I've been trying to get some javascript to work in a block for a week now, took a lot of trila and error but finally got it done thanks to his tips. |
|
|
   |
 |
|
|