/    Sign up×
Community /Pin to ProfileBookmark

javascript writing javascript

Ok so I have some code here and essentially what I want it to do is, I have text files 1.txt, 2.txt… etc that have variables mydata1, mydata2… etc in them respectively. if I load the txt files manually i.e.
<script type = “text/javascript” src=”/home/dillon/Documents/test/1.txt”></script>
<script type = “text/javascript” src=”/home/dillon/Documents/test/2.txt”></script>

Then this script works, however when I try to use a loop for the same purpose it does not work. Is there a way to write javascript with javascript?

<html>
<head>
<script language = “JavaScript” >

function loadz() {
var display = “”
var idisplay
var start = “1”
for(start = 1; start < 10; start++) {

idisplay = (“<script type = “text/javascript” src=”/home/dillon/Documents/test/” + start + “.txt”></script>“)
display = display + ” ” + idisplay
document.getElementById(‘boldStuff’).innerHTML = display
}

}
</script>

<b id=”boldStuff”></b>

</head>
<BODY onLoad=”loadz()”>

<script language=”JavaScript”>

function checkfile()
{

if (window.mydata1 === undefined) {
alert(“mydata is undefined/undeclared”);
}
else {
alert(“mydata is ” + mydata1 + mydata2 + mydata3);
}
}

</script>
Check for mydata
<form name=”myForm”>
<input type=”Button” value=”Check file” onClick=’checkfile()’>
</form>
</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NitecruzexJun 28.2011 — The problem is instead of [CODE]idisplay = ("<script type = "text/javascript" src="/home/dillon/Documents/test/" + start + ".txt"></script>")
display = display + " " + idisplay
document.getElementById('boldStuff').innerHTML = display[/CODE]


it should have been [CODE]idisplay = "<script type = "text/javascript" src="/home/dillon/Documents/test/" + start + ".txt"></script>";
display = display + " " + idisplay;
document.getElementById('boldStuff').innerHTML = display;[/CODE]
Copy linkTweet thisAlerts:
@WolfShadeJun 28.2011 — Also, two things that I noticed:

1. You have a at the end of your closing </script> tag that shouldn't be there.

2. All slashes / need to be escaped with a backslash :
<i>
</i>idisplay = "&lt;script type = "text[COLOR="Red"][/COLOR]/javascript" src="[COLOR="Red"][/COLOR]/home[COLOR="Red"][/COLOR]/dillon[COLOR="Red"][/COLOR]/Documents[COLOR="Red"][/COLOR]/test[COLOR="Red"][/COLOR]/" + start + [COLOR="red"][/COLOR]".txt"&gt;&lt;[COLOR="Red"][/COLOR]/script&gt;";

×

Success!

Help @dirty_dillon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...