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

#26 2011-05-04 22:08:07

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

Re: JavaScript

Okay... What numbers? Like the recent ones? Or something?


Hai.

Offline

 

#27 2011-05-04 22:08:40

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

Re: JavaScript

The numbers from that API page, split by the colon.

Offline

 

#28 2011-05-04 22:10:30

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

Re: JavaScript

Yeah, so all of them?


Hai.

Offline

 

#29 2011-05-04 22:11:32

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

Re: JavaScript

In page1, the first set, page2, the second, page3, the third. That's all.

Offline

 

#30 2011-05-05 06:55:48

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

Re: JavaScript

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  smile


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

Offline

 

#31 2011-05-05 10:16:39

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: JavaScript

Tada!

Code:

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

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#32 2011-05-05 11:21:47

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

Re: JavaScript

Does that make it only report one item?

Offline

 

#33 2011-05-05 19:39:27

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: JavaScript

scimonster wrote:

Does that make it only report one item?

You can use this:

Code:

var projects = get(<insert url here>).split(":"); //Splits the project id's into an array.

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#34 2011-05-05 19:48:27

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

Re: JavaScript

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.


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

Offline

 

#35 2011-05-05 20:15:57

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: JavaScript

IDK

use the
for loop imo


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#36 2011-05-05 20:26:28

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: JavaScript

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?


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#37 2011-05-06 04:55:27

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

Re: JavaScript

What's the code to report item 1 of that array?
I don't know any JS. ^^

Offline

 

#38 2011-05-06 07:25:58

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

Re: JavaScript

@MathWhiz - I was talking about taking the content of the DIV; I agree that the "adding to the array" was just commonsense.

@Scimonster -

Code:

array[0]

gives you the first item (element numbers begin at zero in javascript (and many other languages).


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

Offline

 

#39 2011-05-06 08:00:36

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

Re: JavaScript

Thank you. I'm going to try this out now.  smile
EDIT: Didn't work.  sad

Last edited by scimonster (2011-05-06 08:20:43)

Offline

 

#40 2011-05-06 16:27:43

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

Re: JavaScript

This:

Code:

<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


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

Offline

 

#41 2011-05-09 08:55:57

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

Re: JavaScript

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

Offline

 

#42 2011-05-09 16:52:28

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

Re: JavaScript

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.


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

Offline

 

#43 2011-05-09 18:40:07

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: JavaScript

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  big_smile

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

 

#44 2011-05-09 21:03:06

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: JavaScript

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  big_smile

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

 

#45 2011-05-09 22:51:59

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

Re: JavaScript

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

 

#46 2011-05-10 05:03:33

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

Re: JavaScript

MY NEWEST JAVASCRIPT CODE CHECK OUT MY LINK ITS A FULL FLEDGED CHATBOX WRITTEN WITH JAVASCRIPT AND PHP5  big_smile  .... ..... I HATE CAPS LOCK!!!


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

Offline

 

#47 2011-05-10 19:31:30

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

Re: JavaScript

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

Code:

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

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

Offline

 

#48 2011-05-10 19:39:18

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: JavaScript

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

http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#49 2011-05-12 01:01:09

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

Re: JavaScript

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


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

Offline

 

#50 2011-05-12 01:14:21

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

Re: JavaScript

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

Offline

 

Board footer