473,396 Members | 1,757 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,396 software developers and data experts.

Cannot read ext src array

I have an external file, TestVar.js with a single line.
NewsA("This is a test.","test.pdf","TEST")

Within my HTML I wish to use the array variables from TestVar.js, but
can't seem to get them loaded for use. The following is what I have,
but doesn't work. If I directly place the NewsA array in the script
instead of trying to call it from the js it works just the way I want
it, but I really need the external file. What am I doing wrong?

*************

Start of test 1
<div style="text-align: center;"><font color="#ff0000">
<script language="javascript">
var NewsA=new Array();
</script>
<script type="text/javascript" src="TestVar.js"
language="javascript"><font color="#ff0000">
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2];
document.write(NewsText);document.write(" <a href =
"+NewsPath+">"+NewsLink+"</a>")</script><br>
</font>
</div>
End of Test 1

Mike

*************
Jul 23 '05 #1
6 1744
VK
You cannot mix JavaScript import instructions with inline ones. Change
to:

<script type="text/javascript" src="TestVar.js" ></script>
<script type="text/javascript">
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2];
//...
</script>

As you don't have any guarantees that NewA array will arrive by the
time you address it, the really reliable solution would be:

<script type="text/javascript" src="TestVar.js" ></script>
<script type="text/javascript">
function init() {
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2];
//...
}
window.onload = init;
</script>

Jul 23 '05 #2
shouldn't the function go around the loading of TestVar.js instead of
the assigning variables?

VK wrote:
You cannot mix JavaScript import instructions with inline ones. Change
to:

<script type="text/javascript" src="TestVar.js" ></script>
<script type="text/javascript">
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2];
//...
</script>

As you don't have any guarantees that NewA array will arrive by the
time you address it, the really reliable solution would be:

<script type="text/javascript" src="TestVar.js" ></script>
<script type="text/javascript">
function init() {
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2];
//...
}
window.onload = init;
</script>

Jul 23 '05 #3
OK,
I have tried the script as VK wrote. It comes back with printing
undefined on the web page. Any other ideas?

VK wrote:
You cannot mix JavaScript import instructions with inline ones. Change
to:

<script type="text/javascript" src="TestVar.js" ></script>
<script type="text/javascript">
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2];
//...
</script>

As you don't have any guarantees that NewA array will arrive by the
time you address it, the really reliable solution would be:

<script type="text/javascript" src="TestVar.js" ></script>
<script type="text/javascript">
function init() {
var NewsText = NewsA[0];
var NewsPath = NewsA[1];
var NewsLink = NewsA[2]; //...
}
window.onload = init;
</script>

Jul 23 '05 #4
The other weird thing that happens is it also causes "A Runtime Error
has occurred. Do you wish to Debug? Line:1 Error: Object expected"

Line 1 is <html>. What is this about? Possibly Line 1 of the js file?
Jul 23 '05 #5
Lee
ku_coyote said:

I have an external file, TestVar.js with a single line.
NewsA("This is a test.","test.pdf","TEST")


In addition to what VK has told you, fix that one line
so that it is an array assignment, rather than a function
call to an undefined function.

NewsA=["This is a test.","test.pdf","TEST"];

or some variation of that.

Jul 23 '05 #6
Thanks, That got it. I was thinking that that was how to set up an
array, but I see now what was happening. Thank to all

Lee wrote:
ku_coyote said:
I have an external file, TestVar.js with a single line.
NewsA("This is a test.","test.pdf","TEST")

In addition to what VK has told you, fix that one line
so that it is an array assignment, rather than a function
call to an undefined function.

NewsA=["This is a test.","test.pdf","TEST"];

or some variation of that.

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: overbored | last post by:
I can do this: int asdf; int* zxcv = asdf; but not this: int asdf; int** zxcv = asdf;
9
by: John Guo | last post by:
Hi all, Please help see why this snippet does not compile. Thanks a lot. John #include <string> #include <vector> namespace PatternMsg { std::vector<std::string> msg(17);
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: Martin Lindén | last post by:
I got this example written by David J Gottlieb. Which will not compile. I have previously read in the xml doc with myDataSet.ReadXML(Server.MapPath("bills.xml")) Then when i com to this...
0
by: J?n Sveinsson | last post by:
Hello everyone I have been trying to read and write struct to binary files, I'm using to functions to convert the struct to bytes and bytes to struct, I always receive the following error ...
1
by: Jón Sveinsson | last post by:
Hello everyone I have been trying to read and write struct to binary files, I'm using to functions to convert the struct to bytes and bytes to struct, I always receive the following error ...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
9
by: herobeat | last post by:
Hi all, I'm having a hell of a time with declaring a struct to hold some binary data I'm trying to read from some files on disk. What I would like to do is something like this: public struct...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.