Jump to content

Can Javascript Call PHP Variables? I'm Having an Issue/Conflict


liquidspaceman

Recommended Posts

Didn't know whether to post this in PHP area or Javascript area because it involves a conflict with both. Here goes.

 

I am using this javascript in order for a smiley code to be inserted into the "TEXTAREA"

 

<script type="text/javascript">
window.onload=function() {
pic=document.getElementById('smilies').getElementsByTagName('img');
for(c=0;c<pic.length;c++) {
pic[c].id=c;
pic[c].onclick=function(){
addTextToTextarea(this.id);
}
}
}
function addTextToTextarea(num){

message=['[angry]','[applause]','((atwitsend))','((biggrin))','((bringiton))'];

document.getElementById('ta').value+='\n'+message[num];
}
</script>

And in my PHP page with HTML template: 

<div id="smilies">
<img src=images/smilies/angry.gif>
<img src=images/smilies/applause.gif>
<img src=images/smilies/atwitsend.gif>
<img src=images/smilies/biggrin.gif>
<img src=images/smilies/bringiton.gif>

 

So clicking on one of those smily photos puts the word ((ANGRY) for example into the text area. Then I am using a PHP file to convert it which is:

 

<?php

function callback($buffer)
{
  return (str_replace(
  array('((angry))', '((applause))'),
  array('<img src="images/smilies/angry.gif">', '<img src="images/smilies/applause.gif">'),
  $buffer));
}



ob_start("callback");

?>

 

The problem is, when I include that PHP file, the Javascript changes. Instead of submitting a word like ((angry)) to the TEXAREA, it inserts a IMG SRC link from the PHP file. Really weird. What am I doing wrong? Thanks in adavnce. Included a few screenshots WITH PHP and WITHOUT PHP.

 

I guess what I'm not getting is how a javascript ONCLICK command is calling the PHP file and grabbing the data from that instead of the javascript??? Any ideas? I'm new to this so sorry if it's a dumb question.

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.