| Author |
syntax for include file
|
cara dastoli
Greenhorn
Joined: May 22, 2007
Posts: 13
|
|
Hi, Does anybody know the correct syntax to use an "include" file within javascript? Based on a value I would like to include an html program. In the code below, where it says case 401, I can't seem to get the syntax right no matter what I try. I have tried document.writeln in front of the include, I've tried just about everything I can think of. Any help is appreciated. Thanks, Cara function redirect2(z){ //window.location=temp1[z].value; var myfield = (temp1.options[z].value); alert(myfield); document.isc.myfield2.value = myfield; switch (myfield) { case "400" : document.writeln("Single Switch"); break; case "401" : #include file="my_file.html"; break; case "402" : document.writeln("Dual Switch"); break;document.writeln( } }
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
JavaScript does not have a include. That is normally done with the server. Best thing you can do would be to add an iframe to the page and set the iframe's source. Eric
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
|
|
Or, you could use Ajax to fetch the file and stuff it into the DOM at the appropriate location. But if you are using a server-side language, and don't need a client-side decision, its best to do it on the server. [ July 12, 2007: Message edited by: Bear Bibeault ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
cara dastoli
Greenhorn
Joined: May 22, 2007
Posts: 13
|
|
Originally posted by Eric Pascarello: JavaScript does not have a include. That is normally done with the server. Best thing you can do would be to add an iframe to the page and set the iframe's source. Eric
|
 |
cara dastoli
Greenhorn
Joined: May 22, 2007
Posts: 13
|
|
Originally posted by cara dastoli: [QB]Hi, Thank you. I used the Iframe which worked, however, I would like to display the output on the same page as my original program. How is this possible? Is there an alternative to document.write? My function code is as follows: function redirect2(z){ //window.location=temp1[z].value; var myfield = (temp1.options[z].value); alert(myfield); document.isc.myfield2.value = myfield; switch (myfield) { case "400" : document.write("<iframe src='prod_selection2.html' width='100%'></iframe>"); break; case "401" : document.write("<iframe src='prod_selection3.html' width='100%'></iframe>"); break; case "402" : document.write("<iframe src='prod_selection4.html' width='100%'></iframe>"); break; } } Thanks Again!
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
Yes, you can use docuemt.getElementById to get a handle to your iframe and set its src attribute from the onload event of your page.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
cara dastoli
Greenhorn
Joined: May 22, 2007
Posts: 13
|
|
Originally posted by Ben Souther: Yes, you can use docuemt.getElementById to get a handle to your iframe and set its src attribute from the onload event of your page.
Thank you! Is it possible for you to show an example or direct me to an example of this? I'm not a pro at Javascript. Thanks! Cara
|
 |
 |
|
|
subject: syntax for include file
|
|
|