I want to know something about JavaScript:
Can it read and print info from a webpage?
If yes, can someone give me the code? Thank you.
Last edited by scimonster (2011-05-02 13:17:38)
Offline
If this was on the second page of topics I have posted on it must have been like 4th in misc!
PlainLanguage: bump.
Last edited by scimonster (2011-05-03 04:12:49)
Offline
scimonster wrote:
I want to know something about JavaScript:
Can it read and print info from a webpage?
If yes, can someone give me the code? Thank you.![]()
JavaScript can do prettymuch whatever u want! its a full fledged programming language that is comparable to C++
" A basic tutorial to javaScript and webdesign" < That book taught me Html , CSS , JavaScript in 24 hours so is a must read!!!
Last edited by fanofcena (2011-05-03 07:10:24)
Offline
fanofcena wrote:
scimonster wrote:
I want to know something about JavaScript:
Can it read and print info from a webpage?
If yes, can someone give me the code? Thank you.![]()
JavaScript can do prettymuch whatever u want! its a full fledged programming language that is comparable to C++
![]()
" A basic tutorial to javaScript a … sign" < That book taught me Html , CSS , JavaScript in 24 hours so is a must read!!!
That link doesn't work.
Offline
scimonster wrote:
fanofcena wrote:
scimonster wrote:
I want to know something about JavaScript:
Can it read and print info from a webpage?
If yes, can someone give me the code? Thank you.![]()
JavaScript can do prettymuch whatever u want! its a full fledged programming language that is comparable to C++
![]()
" A basic tutorial to javaScript a … sign" < That book taught me Html , CSS , JavaScript in 24 hours so is a must read!!!That link doesn't work.
![]()
oopz fixed!!!!!!!
Offline
The way I "print" things in javascript is with text boxes, but
document.write("I want to print this");is also a way to do it.
<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function PrintNumbers()
{
var x = (Math.random()*1000)
document.abc.def.vaue = x;
}
</SCRIPT>
</HEAD>
<BODY onLoad="PrintNumber()">
<form name="abc">
<INPUT type="text" name="def"
</form>
</BODY>
</HTML>What code does:
onLoad="PrintNumbers()" means that when the page is loaded, activate the function PrintNumbers
function PrintNumbers: first this declares a variable and sets it to a random number. The next line of code prints that in the text box. Replace it with document.write(x); to actually print it.
Offline
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
Last edited by MoreGamesNow (2011-05-03 07:18:22)
Offline
Oh, I want this for the Scratch Wiki.
Offline
MoreGamesNow wrote:
What are you trying to do?
Read the X Y letters of http://scratch.mit.edu/api/getprojectsb … scimonster
Offline
Sorry, but I'm still not sure what you want, the link led me to a page that was blank, except for a list of numbers. What do those mean/correspond to?
Offline
Those are the IDs of my most recent projects. I would like to have the page read digits 1-7 together, a different page digits 9-15, and then another page digits 17-23.
Offline
Well, you could manually put the numbers into a list, but that is probably not what you have in mind. Other than that, I'd copy that and put it in a text box. I'd do this
<HTML>
<HEAD>
<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"
function SortList()
{
var RealList=list.split(":");
var i;
for(i=0; i<RealList.length; i++)
{
var address = "http://scratch.mit.edu/projects/scimonster/"+RealList[i];
document.write("<a href="+address+">Project "+(i+1)+"</a><BR>");
}
}
</SCRIPT>
</HEAD>
<BODY onLoad="SortList();">
</BODY>
</HTML>Is this what you're trying to make (prints out links to all your projects base on the list you gave me, should be adaptable to any additional projects you make.
Offline
So to answer your question, to read the numbers only, just set a list to the list of numbers with .split(":").
Example: var NewList = OldListofNumbers.split(":");
this will make NewList generate a list (or array) of all the numbers you write (if presented with a colon. If you want to use commas or some other symbol, just replace the colon in the parentheses with that symbol.
Offline
And if I replace the var list="1747295:...." with var list=http://scratch.mit.edu/api/getprojectsbyusername/scimonster
It should work?
Offline
Oh yeah, and how do I read just one item of the list then?
Offline
If you replace list=1747295:1690... with list=http://scratch.mit.edu/api/getprojectsbyusern ame/scimonster, the computer won't know the last digits of the address, unless you're replacing "list" with items that include the numbers:
list=http://scratch.mit.edu/api/getprojectsbyusername/scimonster/1747295:http://scratch...
If you do that, then you can get rid of the whole "var address" line and replace "+address+" with "+list[i]+", and the result should be the same.
On another note, if I were you I'd do this instead:
Don't use "1747295:169071...", but just put it directly into RealList. It would look like this:
RealList = 1747295,1690716,1690245,1677417,167728...
You use commas instead of colons, and you don't encase the whole thing with quotes (though you could put each item/element in quotes, but it doesn't make any difference since they become strings anyway). Then you can get rid of the list.split method.
Offline
No, the api page is the one that has the numbers I want to read- the whole point is that I don't have to update it manually.
Offline
I only want certain characters though. (Sorry for being so difficult.)
Offline
wmays wrote:
I think he's trying to find a way to show his most recent projects on his website and update it dynamicaly.
Actually my wiki page.
Here's my current code on the page:
<big>'''My Latest Projects'''</big></div>
{| border="1" style="width:100%; text-align:center;"
|http://scratch.mit.edu/static/projects/scimonster/1747295_sm.png
|http://scratch.mit.edu/static/projects/scimonster/1690716_sm.png
|http://scratch.mit.edu/static/projects/scimonster/1690245_sm.png
|-
|Xenon- list based setup engine 1
|[http://scratch.mit.edu/projects/scimonster/1690716 no download test]
|[http://scratch.mit.edu/projects/scimonster/1690245 Xenon variable setup]
|-
|The restarting project of the [http://scratch.mit.edu/forums/viewtopic.php?id=59599 Xenon] [[collab]]
|This [[project]] can not be played [[download]]ed, but when I added a When <> is True [[Hat Block]], it didn't work for other people
|The starting project of [http://scratch.mit.edu/forums/viewtopic.php?id=59599 this] collab
|}
With 6 JS subpages, it would be like this, without discriptions:
<big>'''My Latest Projects'''</big></div>
{| border="1" style="width:100%; text-align:center;"
|http://scratch.mit.edu/static/projects/scimonster/{{/jspro1}}_sm.png
|http://scratch.mit.edu/static/projects/scimonster/{{/jspro2}}_sm.png
|http://scratch.mit.edu/static/projects/scimonster/{{/jspro3}}_sm.png
|-
|[http://scratch.mit.edu/projects/scimonster/{{/jspro1}} {{/jsname1}}]
|[http://scratch.mit.edu/projects/scimonster/{{/jspro2}} {{/jsname2}}]
|[http://scratch.mit.edu/projects/scimonster/{{/jspro3}} {{/jsname3}}]
|}
@fg123: But I don't know JS.
Last edited by scimonster (2011-05-06 08:09:30)
Offline
Have the JS read the numbers from the api page and print it, but only some numbers.
Offline