This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-05-02 13:17:26

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

JavaScript

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.  smile

Last edited by scimonster (2011-05-02 13:17:38)

Offline

 

#2 2011-05-03 04:12:34

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

If this was on the second page of topics I have posted on it must have been like 4th in misc!
PlainLanguage: bump.  tongue

Last edited by scimonster (2011-05-03 04:12:49)

Offline

 

#3 2011-05-03 05:11:53

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: JavaScript

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.  smile

JavaScript can do prettymuch whatever u want! its a full fledged programming language that is comparable to C++  tongue

" 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)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#4 2011-05-03 06:25:27

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

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.  smile

JavaScript can do prettymuch whatever u want! its a full fledged programming language that is comparable to C++  tongue

" 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.  hmm

Offline

 

#5 2011-05-03 07:09:51

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: JavaScript

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.  smile

JavaScript can do prettymuch whatever u want! its a full fledged programming language that is comparable to C++  tongue

" 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.  hmm

oopz fixed!!!!!!!


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

#6 2011-05-03 07:15:34

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

The way I "print" things in javascript is with text boxes, but

Code:

document.write("I want to print this");

is also a way to do it.

Code:

<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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2011-05-03 07:17:31

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

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  big_smile

Last edited by MoreGamesNow (2011-05-03 07:18:22)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#8 2011-05-03 07:21:17

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

Oh, I want this for the Scratch Wiki.  wink

Offline

 

#9 2011-05-03 19:51:45

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

What are you trying to do?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2011-05-03 22:20:49

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

MoreGamesNow wrote:

What are you trying to do?

Read the X Y letters of http://scratch.mit.edu/api/getprojectsb … scimonster

Offline

 

#11 2011-05-04 07:23:01

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

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?


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#12 2011-05-04 07:27:15

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

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

 

#13 2011-05-04 20:14:29

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

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

Code:

<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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#14 2011-05-04 20:16:54

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#15 2011-05-04 21:04:18

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

And if I replace the var list="1747295:...." with var list=http://scratch.mit.edu/api/getprojectsbyusername/scimonster
It should work?

Offline

 

#16 2011-05-04 21:39:25

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

Oh yeah, and how do I read just one item of the list then?

Offline

 

#17 2011-05-04 21:39:51

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: JavaScript

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#18 2011-05-04 21:42:23

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

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

 

#19 2011-05-04 21:47:47

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: JavaScript

I see, you want to grab the pages' content dynamically...

http://www.rgagnon.com/jsdetails/js-0035.html

This page seems useful , from google.


Hai.

Offline

 

#20 2011-05-04 21:54:41

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

I only want certain characters though. (Sorry for being so difficult.)

Offline

 

#21 2011-05-04 21:59:45

wmays
Scratcher
Registered: 2008-05-10
Posts: 500+

Re: JavaScript

I think he's trying to find a way to show his most recent projects on his website  and update it dynamicaly.


http://i42.tinypic.com/2z5vcz9.gif
http://phpscripthost.comoj.com/imagescripts/ipimg.php

Offline

 

#22 2011-05-04 22:01:48

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: JavaScript

Certain characters? Then grab the pages content, and sort it into a list, then, delete the ones you don't need. Then print out the ones you need...


Hai.

Offline

 

#23 2011-05-04 22:03:49

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

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.  tongue

Here's my current code on the page:

Code:

<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:

Code:

<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

 

#24 2011-05-04 22:04:44

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: JavaScript

I'm still confused. Over all, what are you trying to do?


Hai.

Offline

 

#25 2011-05-04 22:05:54

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: JavaScript

Have the JS read the numbers from the api page and print it, but only some numbers.

Offline

 

Board footer