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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.