Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am writing a piece of code with 3 files. Ill explain here for simplicity. Files are a,b,c. I have "File a" which is a HTML file "File b" is a htm file "file c" is a php file.

"File a" has "File b" embedded in it by using the HTML include functionality.

The contents of "File b" are designed in "File c".

The PHP+HTML code in file C has a onlcick fucntion which calls a Javascript method on the "file a(HTML)" page. The Javacsript function is written on the "File a". However, I am trying to pass a PHP variable in "File c".

code is as follows:

File a: Javascript function:

function toggle(id,link) {
    alert("here it is!"+link);
    alert("-----"+id);
    var e1 =  id;
    var e = document.getElementById(e1);
    if(e!= null){
        alert("here it is!2");
    if (e.style.display == ''){
        alert("here it is!3");
    e.style.display = 'none';
    link.innerHTML = 'Show Details';
    }else{
        alert("here it is!4");
        e.style.display = '';
        link.innerHTML = 'Hide Details';
        }
    }
}

....

    <div class="lh">  
              <h2>Next Event</h2>
        <!--#include virtual="fileB.htm" -->
             </div>
    </div>

File c:

$dataNew .= "

          <p>
            <h4><i>". $row['description']."</i></h4>
          </p>
          </div>
              <a href=\"javascript:toggle();\" onclick = \****"toggle('".$idDiv."',this)\****">Show Details</a><br><br><img src=\"/ec/sitepics/soldout.jpg\" width=\"150\" height=\"25\" alt=\"Buy Tickets\" /><BR>
            </div>\n";

The PHP variable passed in File c on the BOLD line, is not retrieved in the Javascript function.

What kind of change do I need to do or what would I need to add?

share|improve this question
It might be because of the way you include the file, it's better to include with the server side language (PHP). – Dany Caissy Jun 26 at 21:27
Can you share more from File c? loks ok what I see. (btw,</div>\n"; will probably render not as wished in html) – Sergio Jun 26 at 21:50

1 Answer

I tend to agree with Dany. I'm guessing you primarily work in HTML and Javascript and starting to lever in PHP. I would rename my file a as .php (assuming that's required to associate it with php) then use the PHP include to include file c:

<?php
include("<file c>");
?>

instead of your html incude method.

Remember (because it is server-side) all PHP script is executed - then the resulting output script is delivered to the browser for HTML and javascript processing. This can be hard to get your head round at first - it was for me.:)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.