Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6174231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:43:01+00:00 2026-05-23T23:43:01+00:00

<script> document.getElementById(comment).innerHTML=<?php echo ‘foo bar’; ?>; </script> <div id=comment></div> This should give the word

  • 0
<script>
document.getElementById("comment").innerHTML="<?php echo 'foo bar'; ?>";
</script> 
<div id="comment"></div>

This should give the word “foo bar” in the div element,but its not.Do not know where i’m going wrong. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:43:02+00:00Added an answer on May 23, 2026 at 11:43 pm

    You are trying to use the comment element :

    document.getElementById("comment").innerHTML="...";
    

    Before it is declared :

    <div id="comment"></div>
    

    And firebug shows the following error :

       
    (source: pascal-martin.fr)

    You should :

    • First, create the element in your HTLM
    • And, only after, use it :
      • Either by changing the order you are doing things in your code,
      • Or waiting until the HTML page is fully loaded to execute Javascript.

    If you choose the first solution, your code will look like this :

    <div id="comment"></div>
    <script>
        document.getElementById("comment").innerHTML="<?php echo 'foo bar'; ?>";
    </script> 
    

    And it will work :

    • The foo bar string will be visile
    • And there won’t be any JS error anymore.

       
    (source: pascal-martin.fr)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this script: <script language=Javascript TYPE=text/javascript> var container = document.getElementById('dl'); var seconds =
i took some interest in this script http://www.9lessons.info/2009/06/comment-system-with-jquery-ajax-and-php.html and i see that the ajax
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');
<script type=text/javascript> function myfunction() { if (document.getElementById('myform').value == yes) { document.getElementById('yesinput').style.display = ''; }
<script type=text/javascript> if (window.name == 'default') { window.name = 'a03d01c6c88549c6a7e05c922961271e'; window.document.getElementById('ctl03').click(); } else if
So I have the following JavaScript code: <script type=text/javascript> function clearRadioButtons() { document.getElementById(radiobutton1).checked=; //etc
I've got this script on my website : $(document).ready(function() { function filterPath(string) { return
i have the folowing code: window.document.getElementById(bufferTopic).innerHTML = <img src='einstein/einstein.png' width='800' height='600'><script type='text/javascript' language='javascript'>alert('test');</script> i
I am using this script to insert comment to the database: var http =
I' m trying to enable adding/deleting rows to/from table using folowing code: Script: $(document).ready(function()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.