1

I have this code

if(!document.getElementById('slider_cmp'))
{
    var toolTip = document.createElement("div");
    toolTip.className = "cmp_tips";
    toolTip.id = "cmp_tips";
    toolTip.style.position = "absolute";
    toolTip.style.top =  '145px';
    toolTip.style.left = '50px';
    toolTip.style.display = "none";
    toolTip.style.zIndex = 9999;        
    toolTip.innerHTML = "I NEED TEXT HERE";
    document.body.appendChild(toolTip);
    var sliderDiv = document.createElement("div");
    sliderDiv.className = "slide-out-div";
    sliderDiv.id = "slider_cmp";
    sliderDiv.style.display = "none";
    var handler = '<div id="clickme"></div><div id="slidecontent"></div>';
    sliderDiv.innerHTML= handler;
    document.body.appendChild(sliderDiv);       
    if(cmpLastCat > 0)
    {

I need to put a <?php echo something ?> instead of "I NEED TEXT HERE" in this code... can somebody please help me?

Thank you.

1

2 Answers 2

3

If the JavaScript is within in a PHP-file, you could simply do:

toolTip.innerHTML = "<?php echo $someVariableToPrint; ?>";

The PHP-snippet will be evaluated on the server prior to sending the page to client, so what the client recieves is:

toolTip.innerHTML = "The text in the variable";

Update

Based on the additional info given in your comment, your code would be:

toolTip.innerHTML = "<?php echo CBTxt::_('text here'); ?>";
Sign up to request clarification or add additional context in comments.

12 Comments

Hi What I need to add is - <?php echo CBTxt::_ ( 'text here' ); ?> Can I add this there?
@AlexandruVlas Not sure I understand what you mean? If you want to print some PHP-variable as the text, you simply replace your line toolTip.innerHTML = "I NEED TEXT HERE"; with my line above. You will of course have to change the variable name $someVariableToPrint to the name of the variable that contain the text that you want to print.
@AlexandruVlas toolTip.innerHTML = "<?php echo CBTxt::_ ( 'text here' ); ?>"; should do it. See my updated answer!
Hm... I tried it but it doesn't accept it... I'm looking in source code and it put's the code as a "comment"... <!--?php echo CBTxt::_('texthere'); ?-->
@AlexandruVlas How do you mean "it doesn't accept it"? Get any JS- or PHP-errors?
|
1

Doesn't this work?

toolTip.innerHTML = "<?php echo 'text' ?>";

3 Comments

Hi What I need to add is - <?php echo CBTxt::_ ( 'text here' ); ?> Can I add this there?
Is CBTxt::_ a function? Where's that defined?
My site is in 2 language... CBTxt responds for the translation of the "text here" in more languages...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.