473,322 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

Blue1244
Is there a way you can include code from another document like you can with PHP?
PHP way..
Expand|Select|Wrap|Line Numbers
  1. <?php include('name of document.php'); ?>
Can you do something similar with javascript? If so can you plz help me...
Sep 20 '13 #1

✓ answered by Dormilich

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

6 1408
Dormilich
8,658 Expert Mod 8TB
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.
Sep 20 '13 #2
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?
Sep 20 '13 #3
This is the code I have so far,
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <center><h3>What is an example of a unit rate?</h3></center>
  4. <center><p>A. A ratio showing how many pickles are canned in 4 hours.</p></center>
  5. <center><p>B. A Ratio showing how many problems solved in 1 minute.</p></center>
  6. <center><p>C. A ratio showing how many days it takes to grow one pepper.</p></center>
  7. <center><h5>(Write answers in Caps without the period.)</h5></center>
  8. <center><form><input type="button" value="Answer" onClick="one()"></input></form></center>
  9. <script type="text/javascript">
  10. function one() {
  11. var a= prompt('What is your choice? A, B, or C?');
  12. if(a==B) {
  13. var b= alert('Correct!');
  14. if(b==true) {
  15. require('problem2input.html');
  16. }
  17. }
  18. else {
  19. var d= confirm('Incorrect!');
  20. if(d==true) {
  21. location.reload();
  22. }
  23. else {
  24. location.reload();
  25. }
  26. }
  27. }
  28. </script?
  29.  
This is the code i need to import,
Expand|Select|Wrap|Line Numbers
  1. <center><h3>What is PI used for?</h3></center>
  2. <center><p>A. Area of a Triangle, Circumference, and volume of a box.</p></center>
  3. <center><p>B. Area of a square, area of a circle, and perimeter of a triangle.</p></center>
  4. <center><p>C. Are of a Circle, Circumference, and volume of a cylinder.</p></center>
  5. <center><h5>(Write answers in Caps without the period.)</h5></center>
  6.  
  7.  
  8.  
  9. <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...
Sep 20 '13 #4
Dormilich
8,658 Expert Mod 8TB
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
Sep 20 '13 #5
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.. :)
Sep 20 '13 #6
Dormilich
8,658 Expert Mod 8TB
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.
Sep 21 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bani | last post by:
The following code works fine if it is executed in the same window where "node" belongs. But if node belongs to a document in another window (popup), then I get an error because the created image...
7
by: michael | last post by:
apologies in advance, as not only am i new to learning how to code javascript properly, i'm new to the groups posting thing... i am developing in firefox 1.0+, but will be working in an msie 6.0+...
1
by: Luke Vogel | last post by:
Hi all ... More help needed please. I'm trying to construct an anchor link to another document for my shopping cart web app. something like: <a href="ShoppingBasket.aspx?isbn=<isbndata>...
2
by: Aamir Mahmood | last post by:
Hello, Can I include a control or another aspx file into a container aspx file on the basis of some parameters?\ Like I want ControlA to be inserted in page index.aspx if the submit form has...
9
by: Yeah | last post by:
I have web document A which contains six links that all go to document B. However, all hyperlinks must go to a different location within that document (similar to anchors: A NAME= etc.). How do...
4
by: eh neh | last post by:
Is it possible? If not, then is there any other way you know of in which you can write/send data from a form to another document on the server? Are there any scripts (cgi, perl, etc.) that would...
1
by: mentor | last post by:
I tried this way, but don't work. in current document, first get the node var aNode = document.getElementById("anode"); then, import the node to the other target document, and append it, ...
2
by: cromoglic | last post by:
Hello. I am new to javascript, and need help with something:) I came across this "hack my site"-site, and cant get past level 4 (lol);P I've got the source code: <script src="JavaScript"...
1
by: hollertrek | last post by:
I know this code references Autodesk Inventor (CAD) API, but I'm hoping for a generic solution to my problem with the following error. The error is "object reference not set to an instance of an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.