Is there a way you can include code from another document?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blue1244
    New Member
    • Aug 2013
    • 39

    Is there a way you can include code from another document?

    Is there a way you can include code from another document like you can with PHP?
    PHP way..
    Code:
    <?php include('name of document.php'); ?>
    Can you do something similar with javascript? If so can you plz help me...
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Can you do something similar with javascript?
    depends what you expect the included code to do. right off the bat I know require() (doc) and in the browser you can dynamically load scripts as well (keyword: dependency management).
    but certainly it works somewhat different than PHP’s include. e.g. you cannot include output, only scripts.

    Comment

    • Blue1244
      New Member
      • Aug 2013
      • 39

      #3
      so with what you are talking about can i bring in code from another page to paste a button and a form box onto a page? I'm trying to make that game i was making earlier better(just in case you remember)but, if the answer is correct it creates the next textbox and enter button. is this possible using what you are talking about?

      Comment

      • Blue1244
        New Member
        • Aug 2013
        • 39

        #4
        This is the code I have so far,
        Code:
        <!DOCTYPE html>
        <html>
        <center><h3>What is an example of a unit rate?</h3></center>
        <center><p>A. A ratio showing how many pickles are canned in 4 hours.</p></center>
        <center><p>B. A Ratio showing how many problems solved in 1 minute.</p></center>
        <center><p>C. A ratio showing how many days it takes to grow one pepper.</p></center>
        <center><h5>(Write answers in Caps without the period.)</h5></center>
        <center><form><input type="button" value="Answer" onClick="one()"></input></form></center>
        <script type="text/javascript">
        function one() {
        var a= prompt('What is your choice? A, B, or C?');
        if(a==B) {
        var b= alert('Correct!');
        if(b==true) {
        require('problem2input.html');
        }
        }
        else {
        var d= confirm('Incorrect!');
        if(d==true) {
        location.reload();
        }
        else {
        location.reload();
        }
        }
        }
        </script?
        This is the code i need to import,
        Code:
        <center><h3>What is PI used for?</h3></center>
        <center><p>A. Area of a Triangle, Circumference, and volume of a box.</p></center>
        <center><p>B. Area of a square, area of a circle, and perimeter of a triangle.</p></center>
        <center><p>C. Are of a Circle, Circumference, and volume of a cylinder.</p></center>
        <center><h5>(Write answers in Caps without the period.)</h5></center>
        
        
        
        <center><form><input type="button" value="Answer" onClick="two()"></input></form></center>
        any help and the button isn't working I'll figure it out tomorrow i'm tired...

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          first, <center> is long deprecated.

          second, that’s not what code inclusion is intended for.

          nevertheless, there are several other methods to do that.
          • make a function
          • get the HTML from the server using AJAX
          • get the data from the server (AJAX again) and put it through a templating engine

          Comment

          • Blue1244
            New Member
            • Aug 2013
            • 39

            #6
            I'll just close this discussion and re ask another question on how to use php to use information from a button... i'll just try to figure out how to do all this stuff i need to do with javascript with the php server side code...
            Thank you for the help anyways.. :)

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              and re ask another question on how to use php to use information from a button
              strictly speaking, not at all. there isn’t much information you could put in a button, and on the design side, it doesn’t even make sense to do so.

              Comment

              Working...