The numbers from that API page, split by the colon.
Offline
In page1, the first set, page2, the second, page3, the third. That's all.
Offline
Oh! I have an idea! what if you make the text a DIV (put it into a DIV tag). There should be a way to read the contents of the DIV. I've got to got to jazz band now, but I'll be back to develop this thought
Offline
Tada!
<html>
<head>
<script type="text/javascript">
function get(url)
{
var response = null;
var connection = null;
if (navigator.appName == "Microsoft Internet Explorer")
connection = new ActiveXObject("Microsoft.XMLHTTP");
else
connection = new XMLHttpRequest();
try
{
connection.open("GET", url, false);
connection.send();
if(connection.readyState == 4) response = connection.responseText;
}
catch(e)
{
throw "ERROR: The remote host could not be found or the connection was refused.";
}
return response;
}
function onload()
{
var text = get('http://scratch.mit.edu/api/getprojectsbyusername/scimonster');
var array = text.split(":");
var content = "";
for (var i = 0; i < array.length; i++)
content += array[i] + "<br/>";
document.getElementById("list").innerHTML = content;
}
</script>
</head>
<body onload="onload();">
<div id="list"></div>
</body>
</html>Offline
Does that make it only report one item?
Offline
Well, the MathWhiz seems to have followed my idea, though some of that javascript is beyond me ("try", "catch" and "+="). I'm still not sure what is wrong with just editing an array directly. It wouldn't take any more or less effort than editing a list on the page.
Offline
MoreGamesNow wrote:
Well, the MathWhiz seems to have followed my idea, though some of that javascript is beyond me ("try", "catch" and "+="). I'm still not sure what is wrong with just editing an array directly. It wouldn't take any more or less effort than editing a list on the page.
>< I just split it into an array you can use for whatever then I used a for loop to display it on the page for display. What else do you want?
Offline
What's the code to report item 1 of that array?
I don't know any JS. ^^
Offline
@MathWhiz - I was talking about taking the content of the DIV; I agree that the "adding to the array" was just commonsense.
@Scimonster -
array[0]
gives you the first item (element numbers begin at zero in javascript (and many other languages).
Offline
Thank you. I'm going to try this out now.
EDIT: Didn't work.
Last edited by scimonster (2011-05-06 08:20:43)
Offline
This:
<HTML>
<HEAD>
<STYLE>
A{color:blue; text-decoration:underline}
</STYLE>
<SCRIPT TYPE="text/javascript">
var list="1747295:1690716:1690245:1677417:1677281:1660215:1659776:1588557:1582546:1574540:1543141:1541120:1540857:1539084:1538158:1532177:1518131:1512356:1505665:1495530:1491433:1487985:1487630:1485149:1477427:1460795:1446725:1440454:1440144:1435153:1435147:1430744:1429930:1424257:1423968:1423866:1423583:1417720:1408540:1404706:1399926:1394611:1394563:1394365:1394361:1381117:1381067:1381050:1378830:1376373:1374432:1372825:1349186:1349039:1348557:1340626:1339277:1339247:1334438:1334308:1322548:1170738:1139325:1132172:1132155:1122458:1108971"
var RealList;
function SortList()
{
var i;
RealList=list.split(":");
for(i=0; i<RealList.length; i++)
{
RealList[i] = "http://scratch.mit.edu/projects/scimonster/"+RealList[i];
}
}
function GoToPage()
{
window.location = RealList[0];
}
</SCRIPT>
</HEAD>
<BODY onLoad="SortList();">
<a onClick="GoToPage(0)">Scratch On!</a>
</BODY>
</HTML>Here, just replace the "GoToPage(0) with a different number, the number corresponds to the list.
e.g.
<a onClick="GoToPage(10)">Are you sure you want to?</a>
This may seem kind of weird, but I couldn't find another way to make it link you to the value of a variable without using document.write
Offline
And I replace the var list="1747295:..." with var list=http://scratch.mit.edu/api/getprojectsbyusername/scimonster
?
Offline
Well, the script I gave you adds the items of "list" to "http://scratch.mit.edu/api/getprojectsbyusername/scimonster" to form the actual web address; the result is added to RealList. So you only have to add numbers to the list, not the entire address.
P.S. it might look confusing because I reuse RealList, first to break up "list", and then to store the addresses of your sites.
Offline
MoreGamesNow wrote:
Oh, and as far as reading text, I'm not sure if it can read direct text from a web site, but it can definitely report the value of a text box.
Using the text box above, the value is found simply with this: document.abc.def.value
So to make an alert box with the value of the text box: alert(document.abc.def.value);
To learn more, go to w3schools here, or just keep asking me![]()
I have a Javascript question:
How do we set a textbox's value to another value?
EDIT: Oh, it's working now. I placed the script in the wrong place.
Last edited by rdococ (2011-05-09 18:42:53)
Offline
rdococ wrote:
MoreGamesNow wrote:
Oh, and as far as reading text, I'm not sure if it can read direct text from a web site, but it can definitely report the value of a text box.
Using the text box above, the value is found simply with this: document.abc.def.value
So to make an alert box with the value of the text box: alert(document.abc.def.value);
To learn more, go to w3schools here, or just keep asking me![]()
I have a Javascript question:
How do we set a textbox's value to another value?
EDIT: Oh, it's working now. I placed the script in the wrong place.
document.getElementByID("TEXTBOX_ID_HERE").innerHTML = "HI. THIS IS WHERE YOUR TEXT GOES :3";
Last edited by ThePCKid (2011-05-09 21:03:39)
Offline
MoreGamesNow wrote:
Well, the script I gave you adds the items of "list" to "http://scratch.mit.edu/api/getprojectsbyusername/scimonster" to form the actual web address; the result is added to RealList. So you only have to add numbers to the list, not the entire address.
P.S. it might look confusing because I reuse RealList, first to break up "list", and then to store the addresses of your sites.
No, it should add the value of the web-page to "list."
Offline
MY NEWEST JAVASCRIPT CODE CHECK OUT MY LINK ITS A FULL FLEDGED CHATBOX WRITTEN WITH JAVASCRIPT AND PHP5
.... ..... I HATE CAPS LOCK!!!
Offline
scimonster wrote:
No, it should add the value of the web-page to "list."
I'm pretty sure there is no way to read straight from a webpage, unless it is all in a div. To find the text in a div just use document.getElementById("id").innerText.
The other options I've mentioned above:
a) textbox
b) just edit the actual javascript
What exactly are you trying to do? Why wouldn't editing the javascript work?
Anyway, here is the code for using the contents of a DIV
<HTML>
<HEAD>
<STYLE>
A{color:blue; text-decoration:underline}
</STYLE>
<SCRIPT TYPE="text/javascript">
var RealList;
function SortList()
{
var i;
RealList=document.getElementById("list").innerText.split(":");
for(i=0; i<RealList.length; i++)
{
RealList[i] = "http://scratch.mit.edu/projects/scimonster/"+RealList[i];
}
alert(RealList);
}
function GoToPage()
{
window.location = RealList[0];
}
</SCRIPT>
</HEAD>
<BODY onLoad="SortList();">
<DIV id="list">
1747295:1690716:1690245:1677417:1677281:1660215:1659776:1588557:1582546:1574540:1543141:1541120:1540857:1539084:1538158:1532177:1518131:1512356:1505665:1495530:1491433:1487985:1487630:1485149:1477427:1460795:1446725:1440454:1440144:1435153:1435147:1430744:1429930:1424257:1423968:1423866:1423583:1417720:1408540:1404706:1399926:1394611:1394563:1394365:1394361:1381117:1381067:1381050:1378830:1376373:1374432:1372825:1349186:1349039:1348557:1340626:1339277:1339247:1334438:1334308:1322548:1170738:1139325:1132172:1132155:1122458:1108971
</DIV>
<a onClick="GoToPage(0)">Apple</a>
</BODY>
</HTML>Offline
USE JQUERY:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript">
function loadProjects()
{
$.get("http://scratch.mit.edu/api/getprojectsbyusername/scimonster",{},function(data)
{
var projectNumbers = data.split(":")
doSomethingWith(projectNumbers)
})
}
Offline
fullmoon wrote:
USE JQUERY:
Code:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script> <script type="text/javascript"> function loadProjects() { $.get("http://scratch.mit.edu/api/getprojectsbyusername/scimonster",{},function(data) { var projectNumbers = data.split(":") doSomethingWith(projectNumbers) }) }
Dont u think JQuery will sorta confuse em ? ? ? ?
Offline
fanofcena wrote:
fullmoon wrote:
USE JQUERY:
Code:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script> <script type="text/javascript"> function loadProjects() { $.get("http://scratch.mit.edu/api/getprojectsbyusername/scimonster",{},function(data) { var projectNumbers = data.split(":") doSomethingWith(projectNumbers) }) }Dont u think JQuery will sorta confuse em ? ? ? ?
Yes.
Offline