www.webdeveloper.com
Results 1 to 13 of 13

Thread: [RESOLVED] Y U now work ??

  1. #1
    Join Date
    Jul 2012
    Posts
    41

    resolved [RESOLVED] Y U now work ??

    so in a search of working method to change div content after an hour i came back to w3school website and copied code from there , and that bloody thing still doesn't work. Am i doing it wrong ?
    button
    PHP Code:
    echo "
    <div class=\"mainmenu\">
    <button onclick=\"displayDate()\" id=\"buttons\" type=\"button\">asdasd</button>
    </div>
    </br>
    "

    div block
    PHP Code:
    echo"
    <div id=\"teams\">
    <p id=\'test\'>asdasd</p></div>
    "

    function
    PHP Code:
    echo "
    <script type=\"text/javascript\">
    function displayDate()
    {
    document.getElementById(\"test\").innerHTML=Date();
    }
    </script>
    "

    any ideas ?

  2. #2
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    PHP Code:
    echo "
    <script type=\"text/javascript\"> 
    function displayDate() 

    document.getElementById(\"test\").innerHTML=Date(); 

    </script>
    "

    Try this

    PHP Code:
    echo "
    <script type=\"text/javascript\"> 
    function displayDate(){ alert(\"button Clicked\") } 
    </script>
    "

    and see if it Shows up

    also if your trying to use php date function it would look like this

    PHP Code:
    echo "
    <script type=\"text/javascript\"> 
    function displayDate() 

    document.getElementById(\"test\").innerHTML="
    .Date('Y-m-d')."; 

    </script>
    "

    Last edited by Nvenom; 07-25-2012 at 08:58 AM.
    Albert Einstein ~ "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction."

    Things To help you on this Site

    1. Place all php code in [php] Tags
    2. Place all html code in [html] Tags
    3. Remember to mark all your Threads Resolved using thead tools at the top when your problem is solved

  3. #3
    Join Date
    Jul 2012
    Posts
    41
    Yes it does, but i copied the function straight from the w3school and changed only the ID of the <p> any ideas why its not working ?

  4. #4
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    Post the link to where you got it on W3school
    Albert Einstein ~ "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction."

    Things To help you on this Site

    1. Place all php code in [php] Tags
    2. Place all html code in [html] Tags
    3. Remember to mark all your Threads Resolved using thead tools at the top when your problem is solved

  5. #5
    Join Date
    Nov 2007
    Posts
    409
    Your code works fine in the latest FireFox and IE8.

    Compare the HTML below with what your rendered HTML to see what you might have wrong. Have you checked the error console to see if it is throwing an error?
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Demo</title>
    </head>
    <body>
    <div class="mainmenu">
    <button onclick="displayDate()" id="buttons" type="button">asdasd</button>
    </div>
    <div id="teams">
    <p id='test'>asdasd</p></div>
    </br> 
    
    
    <script type="text/javascript">
    function displayDate() {
    	document.getElementById("test").innerHTML=Date();
    }
    </script> 
    
    </body>
    </html>

  6. #6
    Join Date
    Jul 2012
    Posts
    41
    Quote Originally Posted by nap0leon View Post
    Your code works fine in the latest FireFox and IE8.

    Compare the HTML below with what your rendered HTML to see what you might have wrong. Have you checked the error console to see if it is throwing an error?
    I created an html file with the same code and it works. But when i do it in .php with echo it doesn't work, in fact i dont have any .html files only one .php and one .css in my "working directory". And i dont know how to open error console.

    heres my full .php file

    PHP Code:
    <link rel="stylesheet" type="text/css" href="styles.css" />


    <?php
    // function for changing div
    echo "
    <script type=\"text/javascript\">
    function displayDate()
    {
    document.getElementById(\'test\').innerHTML=Date();
    }
    </script>
    "
    ;
    // main picture
    echo "
    <div class=\"mainpic\">
    <img class=\"emblem\" src=\"pic/emblem.png\"/>
    </div>
    "
    ;

    // main menu
    echo "
    <div class=\"mainmenu\">
    <a href=\"teams.php\"><input id=\"buttons\" type=\"button\" value=\"Teams\"></a>
    <a href=\"tour.php\"><input id=\"buttons\" type=\"button\" value=\"Tournaments\"></a>
    <button onclick=\"displayDate()\" id=\"buttons\" type=\"button\">asdasd</button>
    </div>
    </br>
    "
    ;

    // div block
    echo"
    <div id=\"teams\">
    <p id=\'test\'>asdasd</p></div>
    "
    ;
    ?>
    Last edited by Stobor; 07-25-2012 at 09:20 AM.

  7. #7
    Join Date
    Jan 2009
    Posts
    3,346
    <p id=\'test\'>asdasd</p></div>
    I bet that's your problem.

    Code:
    <p id=\"test\">asdasd</p></div>

  8. #8
    Join Date
    Jul 2012
    Posts
    41
    Nope. still doesn't work.

  9. #9
    Join Date
    May 2011
    Location
    With Hobbits
    Posts
    125
    Dosent work because you have \ next to ' and that causes the id of \'test\' to be read as 'test\' in Javascript so use this instead

    PHP Code:
    <link rel="stylesheet" type="text/css" href="styles.css" /> 


    <?php 
    // function for changing div 
    echo 
    <script type=\"text/javascript\"> 
    function displayDate() 

    document.getElementById(\'test\').innerHTML=Date(); 

    </script> 
    "

    // main picture 
    echo 
    <div class=\"mainpic\"> 
    <img class=\"emblem\" src=\"pic/emblem.png\"/> 
    </div> 
    "


    // main menu 
    echo 
    <div class=\"mainmenu\"> 
    <a href=\"teams.php\"><input id=\"buttons\" type=\"button\" value=\"Teams\"></a> 
    <a href=\"tour.php\"><input id=\"buttons\" type=\"button\" value=\"Tournaments\"></a> 
    <button onclick=\"displayDate()\" id=\"buttons\" type=\"button\">asdasd</button> 
    </div> 
    </br> 
    "


    // div block 
    echo
    <div id=\"teams\"> 
    <p id='test'>asdasd</p></div> 
    "

    ?>
    Albert Einstein ~ "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction."

    Things To help you on this Site

    1. Place all php code in [php] Tags
    2. Place all html code in [html] Tags
    3. Remember to mark all your Threads Resolved using thead tools at the top when your problem is solved

  10. #10
    Join Date
    Nov 2007
    Posts
    409
    Ahh - a php issue, not a javascript issue.

    BTW, when I say "rendered HTML" I am referring to you doing a "View Source" in your web browser to see what your HTML actually looks like. If the issue is an extra \ somewhere in the IDs, you would see it in "View Source".

    Error Console is typically in something named like "Developer Tools" which is typically accessed by pressing [F12] in your browser. If you are using FireFox, I strongly encourage installing the FireBug add-on.

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,245
    Consider using HEREDOC quoting so that you don't have to worry about escaping quotes.
    PHP Code:
    <?php
    echo <<<END
    <p id="do_not_need_slashes">This is a test</p>
    <p>And it interpolates 
    $variables just like double quotes</p>
       <p>You can indent all you want, EXCEPT the ending string can not have ANY leading white-space:</p>
    END;

    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Jul 2012
    Posts
    41
    It works everywhere like that why shouldn't it work with \'test\' in particular ?

    Quote Originally Posted by nap0leon View Post
    Ahh - a php issue, not a javascript issue.

    BTW, when I say "rendered HTML" I am referring to you doing a "View Source" in your web browser to see what your HTML actually looks like. If the issue is an extra \ somewhere in the IDs, you would see it in "View Source".

    Error Console is typically in something named like "Developer Tools" which is typically accessed by pressing [F12] in your browser. If you are using FireFox, I strongly encourage installing the FireBug add-on.
    did that , thankyou

    Quote Originally Posted by NogDog View Post
    Consider using HEREDOC quoting so that you don't have to worry about escaping quotes.
    PHP Code:
    <?php
    echo <<<END
    <p id="do_not_need_slashes">This is a test</p>
    <p>And it interpolates 
    $variables just like double quotes</p>
       <p>You can indent all you want, EXCEPT the ending string can not have ANY leading white-space:</p>
    END;

    ?>
    wow didnt know you can do that. thankyou
    Last edited by Stobor; 07-25-2012 at 11:11 AM.

  13. #13
    Join Date
    Jul 2012
    Posts
    41
    Thankyou all for helping HEREDOC did the job.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles