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

#1 2012-01-19 20:03:56

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

I need some javascript help.

Finally! I got it to work! This is the code that got it to work:

Code:

<html><head><title>Test log in screen</title>
<style type="text/css">
#login {
    float: none; 
    text-align: left; 
    width: 410px; 
    margin: 0px auto; 
    margin-top: 134px; 
    background: #1AD00B; 
    border: 4px solid #12B20A; 
    font-family: arial; 
    color: #D0170B; 
    padding: 0 0 15px 25px; 
    opacity: .85; 
    filter: alpha(opacity=85);
}

#title {
    font-size: 24px; 
    font-weight: bold; 
    display: block; 
    width: 385px; 
    border-bottom: 2px solid #0506FF; 
    margin-bottom: 30px;
}

#submit {
    background: #04E7CB; 
    color: #04E7CB; 
    font-size: 18px; 
    font-weight: bold; 
    padding: 4px; 
    margin-left: 5px;
}

#p {
    border: 5px solid #FFF80A; 
    font-size: 18px; 
    padding: 5px; 
    width: 305px;
}
</style>
<!--[if IE]>
<style type="text/css">

#login {
    padding: 25px 25px 15px 25px;

}

#p {
    width: 270px;
    height: 35px;
}

#submit {
    padding: 0px;
    margin-left: 5px;
    height: 38px;
    position: relative;
    top: 2px;
    color: #000000;
}

</style>
<! [endif]-->

</head>
<body style="background: #FFCA05; text-align: center; margin: 0; padding: 0;">
  <div id="login"> 

<form>
<p id="title">Login here:</p>

<form>
<p>User Name :
  <input type="text" name="text2">
</p>
<p>Password :
<input type="password" name="text1">
</p>
<p><input type="button" value="Submit" name="Submit" 

onclick=javascript:validate(text2.value,"Happy",text1.value,"Sad") >
</p>

</form>
<script language = "javascript">

function validate(text1,text2,text3,text4)
{
 if (text1==text2 && text3==text4)
 load('What to load when it works.htm');
 else
 {
  load('what to do when it's a failure.htm');
 }
}
function load(url)
{
 location.href=url;
}
</script>

Thanks to everybody who tried to help. I can't believe I got it myself. I would like to give special thanks to MoreGamesNow (you know - the rubix cude person). He/She knows a lot about the subject and was always checking back in to see if there were more answers to be answered (if you know what I mean). The best way to show my happiness -->  big_smile   smile   big_smile   smile   big_smile  Sadly, the images just can't explain it. I am just so happy... Thanks for everything!

Last edited by PullJosh (2012-01-27 07:45:08)


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#2 2012-01-19 20:22:07

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: I need some javascript help.

try

Code:

<SCRIPT TYPE="test/javascript">

instead of

Code:

<SCRIPT LANGUAGE="JavaScript">

http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#3 2012-01-19 21:09:03

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

Re: I need some javascript help.

nathanprocks wrote:

try

Code:

<SCRIPT TYPE="test/javascript">

instead of

Code:

<SCRIPT LANGUAGE="JavaScript">

no.

also,

Code:

str.link

maybe try

Code:

window.location

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

Offline

 

#4 2012-01-19 21:10:53

nickbrickmaster
Scratcher
Registered: 2010-02-02
Posts: 500+

Re: I need some javascript help.

try

Code:

<script type="text/javascript">

plus ur tags shouldnt be in caps.


Ask me what I'm doing, wait an hour than roll a die, if it's 4-6, I'm playing Skyrim, if it's 1, I'm eating, if it's 2-3 I'm programming.
Steam: nickbrickmaster | RotMG: PwnThemAll | Minecraft: nickbrickmaster | League Of Legends: BaneOfTitans

Offline

 

#5 2012-01-19 21:11:59

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

Re: I need some javascript help.

nickbrickmaster wrote:

try

Code:

<script type="text/javascript">

plus ur tags shouldnt be in caps.

lol, this is tru


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

Offline

 

#6 2012-01-19 21:39:09

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

Re: I need some javascript help.

Code:

if(TestVar == "hello")

First thing I saw was: add quotation marks.

And if you want it to automatically go to a different site, just use

Code:

window.location = "http://what_ever_the_url_is.com"

Edit: Sorry for that last bit, it is a bit redundant as bbbeb also posted it.

I also suggest using "text/javascript" whenever possible, as it is more up-to-date I believe.  May I ask why you have a method="GET" but not an action?  Unless you're using php - and from what you've shown us, you're not -, you don't need to have a "method".  Just <form name="myform">.

Code:

<HTML>
<HEAD>
<TITLE>Test Input</TITLE>
<SCRIPT LANGUAGE="text/javascript">
function testResults ()
{
     var TestVar = document.myform.inputbox.value;
     if(TestVar == "hello")
     {
          window.location = "http://www.aWebsite.com";
     }
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox">
<INPUT TYPE="button" Value="Click" onClick="testResults()">
</FORM>
</BODY>
</HTML>

Last edited by MoreGamesNow (2012-01-19 21:47:43)


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

Offline

 

#7 2012-01-20 16:50:14

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: I need some javascript help.

<HTML>
<HEAD>
<TITLE>Test Input</TITLE>
<script type="text/javascript">
function testResults (form) {
    var TestVar = form.inputbox.value;
    if(TestVar == "hello")
  {
  window.location.href = "http://google.com";
  };
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="myform" ACTION="">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE=""><P>
<INPUT TYPE="button" NAME="button" Value="Click" onClick="testResults(this.form)">
</FORM>
</BODY>
</HTML>


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#8 2012-01-20 23:08:16

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

Re: I need some javascript help.

you don't need ".href".


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

Offline

 

#9 2012-01-22 10:08:29

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

Re: I need some javascript help.

Use double equals sign to check equality, and a single to set a variable.  wink

Offline

 

#10 2012-01-22 12:45:39

PullJosh
Scratcher
Registered: 2011-08-01
Posts: 500+

Re: I need some javascript help.

scimonster wrote:

Use double equals sign to check equality, and a single to set a variable.  wink

Thanks. I knew that, but there are such things as typos... I'm not saying that your comment wasn't useful. It definitely was.  wink


http://www.blocks.scratchr.org/API.php?action=text&amp;string=I'm_on_vacation!&amp;xpos=155&amp;ypos=90&amp;font_size=30&amp;bgimage=http://imageshack.us/a/img339/7215/sspeechsigapiforwords.png

Offline

 

#11 2012-01-22 20:18:55

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

Re: I need some javascript help.

why use this.form? just use myform  tongue


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

Offline

 

#12 2012-01-22 20:35:58

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

Re: I need some javascript help.

You don't want document.getElementById('p');, you want document.loginForm.passwerd.value.  Having said that, you may be able to get away with document.getElementById('p').value

Edit:  I said "may be able to" because it has been a while since I have used anything other than document.formname.inputname.value

Last edited by MoreGamesNow (2012-01-22 20:37:05)


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

Offline

 

#13 2012-02-01 21:16:56

cau2134
Scratcher
Registered: 2011-10-22
Posts: 29

Re: I need some javascript help.

<script type="text/javascript">


http://mag.racked.eu/cimage/i9002/Achievement+get%21/I.39.m+watching+you%21/mca.png

Offline

 

Board footer