picking up a path in a javascript file - javascript

I need some help with my js file. I an using a bit of javascript to show some xml on a page and I need to reference the right xml file according to the page that it is on. e.g.
<script>
xml=loadXMLDoc("product.xml");
</script>
I have the all the xml files named as different products and have printed out the reference to the xml on the page that it should be on
<div id="product">/xmlfolder/item001.xml</div>
What I need to do is somehow reference the path on the page to the javascript. Is this possible?
Thanks

Do you mean
xml=loadXMLDoc(document.getElementById('prodct').innerHTML);

Related

Only last javascript file linked with script tag is working

I linked all the javascript files in the header.php at atime. I included header.php in all pages
When I link the javascript files like this
<script src='js/home.js'></script>
<script src='js/disc.js'></script>
<script src='js/que.js'></script>
only last file js/que.js is working.
Make sure that the 'src' is referring to the correct file directory where the script is located. If you are using an IDE such as VS, then you may drag the file into the code and the IDE will automatically create the reference for you.
Unless you have problem with directory structure or you file name does not match with src attribute of script tag, there should not be any problem with. Please try to use type="text/javascript" and make sure your script tags are after header tag or just before </body> tag. Also keep sequence of files loading if any file depends on another file variable or any function. If it still does not work use try to see if there is any error in your code in console window.
I now I'm going to get voted down for this but oh well. I don't have enough points to comment which is what I would do but..oh well.
Okay it depends on what the scripts are doing. If you link the scripts in the head for you HTML page, and try a var element = document.getElementById("theID"); this will return null due to the fact that the browser has yet to read the HTML and hasn't had a chance to create a DOM (Document Object Model) tree. For a problem like this check out
<script>
function load() {
console.log("load event detected!");
}
window.onload = load;
</script>
This will assign window to an event/callback that will be invoked after the page has had time to load.
Look at where your JavaScript is used, and what it should be doing. Would those elements be rendered yet. Are you writing functions but not actually calling them (this happens A LOT)? It would be better if you described what the code was doing and your experience with HTML and JavaScript. Remember that the browser interprets the JavaScript as it encounters it, you can put script tags anywhere in your HTML file, not just in the head. Also are the .js files in the same directory as the HTML file or are the two non working .js files in the same directory as "js/que.js"? If not move them to the same file or use a relative or absolute path.

Referencing js files from an html file in Quickbase

I am trying to build a flot chart using data from Quickbase. In order to accomplish this I have to be able to reference the flot.js files. In my html page I have scripts that call the js files located in Quickbase where the src is equal to the url link to the read-only version of the js file. However, the html page does not seem to be referencing the js pages. Does anyone have any suggestions? Thanks.
Use a script similar to this, but replace the part before .quickbase, the db, and the pagename value.
<script src="https://haversineconsulting.quickbase.com/db/bipznmwx8?a=dbpage&pagename=myscript.js"></script>
Or
<script src="bipznmwx8?a=dbpage&pagename=myscript.js"></script>
See https://quickbase-community.intuit.com/questions/811560-javascript-libraries

Extract javascript from JSP to JS file

I'm trying to refactor parts of our front-end at the moment, using Intellij. We have a lot of javascript that is within our JSPs. I'd like to be able to extract from the JSP into a .js fil and replace it with a script tag referencing that file. I know how to extract to an 'includes' file, but I'd like a way of extracting and replacing the code with a proper script tag.
Does anyone know of a plugin that can accomplish this quickly and easily? (Or a pre-existing function in Intellij that I'm unaware of)
Please vote for this issue (it's 5 years old and had zero votes).
just create one file with .js extension copy and paste your js codes with their function names. then include that file in your jsp project header section.
eg:
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
thats all..

HTML5 with javascript to parse and display textfile

I have an HTML5 page (index.html), and I need to display the contents of a .txt file (p001wide.txt). Both are on the server in the same directory.
The text file is generated from a CMS, so I cannot change the format of that file.
In the .txt file is a variable named widetxt. I need to display the contents of the widetxt variable on the page.
What do I need to do to parse the the textfile and display it in the HTML page?
Do I need to use javascript, and if so, how?
Hm, I found this question which appears to be similar to yours as far as reading a file goes. As for parsing though why not use a database such as MySQL to store your data? This way you can quickly add and query through your data.
As both your index file and the text file you wish to read reside on the server you should be able to read the text file on the server and insert what you wish from it into the index file using PHP.
See http://www.w3schools.com/php/php_file.asp for a tutorial on how that can be done without resorting to client side script.
If you cannot alter your index file on the server and can put a PHP file on the server you can use AJAX to ask your PHP file to read the contents of the text file and return it to you. Then you would use javascript to insert it as you wish. I presume that you can alter the index file because otherwise you could not alter its javascript either.
You can do this with JavaScript, you basically need to learn how to read and write files (and you mention the variable inside, this would be parsing). Start reading here - http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm other information, just Google read write files javascript, or parsing text with javascript.
Best of luck!

JS Include is not working

I have moved an large piece of JS code form my header file to it's own .js file.
I'm trying to include it with:
<script src="includes/js/test.js" type="text/javascript"></script>
The JS code is not loaded, what could be wrong?
One possible reason is that the path is wrong. Remember that the path as you've written it will be interpreted relative to the current URL. So if this code appears on a page that is accessed at
http://www.example.com/example1/index.html
then the browser will request the javascript file from
http://www.example.com/example1/includes/js/test.js
which may not be what you want. A better approach may be to use a link that is based on the root: that is, if you change it to
<script src="/includes/js/test.js" type="text/javascript"></script>
then it will always look in
http://www.example.com/includes/js/test.js
no matter where the link appears.
If I had to guess based on the information you've provided, I'd say there's probably a syntax error in the external .js file or the page isn't finding the file from the URL provided. That's usually the problem I experience when I move large pieces of code from one file to another.

Categories