Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 44
  1. #1
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts

    include and the .innerHTML

    Ok I want to be able to include a html file into my template.

    I want the php include to work when I press a button that will put the include into a specific element with the document.getElementById("").innerHTML method in javascript. I want the include to be able to be more then a single line. For example I want to be able to write my code like this

    <div>
    some text
    </div>

    and not have to write it like this

    <div>some test</div>

    Thanks
    Shelby

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    Any reason why you are against the page load?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Simple reason is it makes for less load time for slower internet users if done properly.
    Basically so users with dialup wont die when visiting my website.
    yes believe it or not but lots of people still use dialup.

    Ok not exactly what I was looking for. Was looking for a script in PHP that will turn the multi line page into single line before it includes it. so sorta like include one line of the file at a time. This I know can be done as I saw it done about 3 months back but forget where the heck I saw it.
    Last edited by MrEnder; 03-02-2010 at 02:36 AM.

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by MrEnder View Post
    Ok not exactly what I was looking for.
    Yes it is. You need AJAX to fetch the file contents.

    Was looking for a script in PHP that will turn the multi line page into single line before it includes it. so sorta like include one line of the file at a time.
    PHP couldn't give a toss whether you code it all on one line or not. Write the content of that file however you please. It'll all be output when the file is run. Just run a preg_replace on the code before you output it if you want all the content on one line, i.e:

    Code:
    <?php
    
    $output = <<<output
    <div>
    Whatever you want here.
    </div>
    output;
    
    exit(preg_replace("#[\n\r]#", '', $output));
    
    ?>
    Last edited by MattF; 03-02-2010 at 02:56 AM.

  • #5
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    PHP dont give a crap but JS sure as hell does.

    try this

    document.getElementById("someId").innerHTML = "some text";

    then try this

    document.getElementById("someId").innerHTML = "some

    text";

    it wont work -_-

    now I want to include in the "" part its the ONLY way it can be done trust me on it.

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by MrEnder View Post
    PHP dont give a crap but JS sure as hell does.

    try this

    document.getElementById("someId").innerHTML = "some text";

    then try this

    document.getElementById("someId").innerHTML = "some

    text";

    it wont work -_-

    now I want to include in the "" part its the ONLY way it can be done trust me on it.
    So, did you actually bother to read all of my post above, or did you just read the first part and start responding? You've already been given your answer.

  • #7
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by MattF View Post
    So, did you actually bother to read all of my post above, or did you just read the first part and start responding? You've already been given your answer.
    I am still working to see if it will work. I destroyed my template somehow and my sizing is all screwed up so haven't gotten back to trying that yet.

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by MrEnder View Post
    I am still working to see if it will work.
    It does.

  • #9
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by MattF View Post
    It does.
    document.getElementById("action1").innerHTML = '<?php $output = <<<output include "test.html" output; exit(preg_replace("#[\n\r]#", "", $output)); echo $output; ?>';

    what I do wrong?

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You are making this harder than it has to be. You are using exit() instead of echo. Exit will stop all processing of your php including the php page you are running the code on. The link I gave you is exactly what you need. It can load external files including php files dynamically with the click of a link.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    You are making this harder than it has to be. You are using exit() instead of echo. Exit will stop all processing of your php including the php page you are running the code on. The link I gave you is exactly what you need. It can load external files including php files dynamically with the click of a link.
    ya but it doesnt use a php include its Ajax... nothing wrong with Ajax now Ajax is great but the problem is that I'm supposed to use a include somewhere in my assignment and its the only spot I could think to use it. And I can use it but I came across that stupid complication.

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Okay now I see. This is an assignment. Now we see why you were trying to make things complicated. For heredoc to work properly the EOF (output;) needs to be on its own line. I suggest moving all of your php to another file and then use include() at the top of your page however do not echo anything in this file. You would need to echo your output in your JS innerHTML part. I've given you a hint on what you've done wrong so hopefully you can fix it. Good luck. FYI no one is just going to give you code either as this is an assignment.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Okay now I see. This is an assignment. Now we see why you were trying to make things complicated. For heredoc to work properly the EOF (output needs to be on its own line. I suggest moving all of your php to another file and then use include() at the top of your page however do not echo anything in this file. You would need to echo your output in your JS innerHTML part. I've given you a hint on what you've done wrong so hopefully you can fix it. Good luck. FYI no one is just going to give you code either as this is an assignment.
    Lol my assignment is done ^.^

    http://opentech.durhamcollege.ca/~pu...n2201/lab4.php

    I just went overboard on it and decided to add a WHOLE lot more. ^.^ I'm not even supposed to touch javascript ^.^ lol but it was just to hard to resist =[

    I was supposed to include my header and footer... I decided to include my body instead... it seemed like more fun...

    So now I'm off learning on my own trying to get ahead of my class ^.^

    Ok now so far ive only learned includes and variables and requireds oh ya and echos... but ive been doing JS since I was like 13... so I work with it a lot more...

    So ya part of why I decided to do it this way is about 3 months ago I saw a script to do exactly what I want but I had no use for it so didnt write it down or remember where i found it =[ but now I came across a great opportunity to use it now that I know what an include is exactly ^.^

    Only problem is my php knowledge sucks so im stabbing in the dark -_-

  • #14
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    man that one script that guy gave me doens't work in my context at all -_- I've fiddled with it for a good dang hour now =\

  • #15
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post your latest code. All of it not just snippets. Please use [php][/php] tags around the code you put.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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