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

#1 2012-05-28 12:16:18

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

A Javascript problem... Yet again (x2)

I'm starting to feel less smart by the minute. Anyway, I have yet another Javascript problem. This one needs to be answered quickly, so just do what you guys do best: answer my questions quickly. Anyway, here's my code:

Code:

<form>
<p>Password :
<input type="password" name="text1" id="Pass">
</p>
<p><input type="button" value="Submit" name="Submit" onclick=javascript:check() >
</p>

</form>
<script>
var Password = "Pop";

function check()
{
 if (document.getElementById('Pass') == Password)
 load('Game.htm');
else {
  alert('Incorect username/password. Please try again.');
 }
}
function load(url)
{
 location.href=url;
}
</script>

I left out all the fun CSS and things like that. It's supposed to Bring you to some other document if you type "Pop" as the password. It always says I'm wrong.

I hope you guys can help (like you always have)!


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-05-28 12:20:37

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: A Javascript problem... Yet again (x2)

document.getElementById('Pass').value will work

getElementById just returns the element itself, you then need to ask for its value.

P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.  wink

Last edited by Hardmath123 (2012-05-28 12:22:31)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3 2012-05-28 12:37:30

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

Re: A Javascript problem... Yet again (x2)

Hardmath123 wrote:

document.getElementById('Pass').value will work

getElementById just returns the element itself, you then need to ask for its value.

P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.  wink

Awesome! Thanks! (*Whistles* "I knew those guys were quick").  smile


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

 

#4 2012-05-28 12:41:34

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: A Javascript problem... Yet again (x2)

PullJosh wrote:

Hardmath123 wrote:

document.getElementById('Pass').value will work

getElementById just returns the element itself, you then need to ask for its value.

P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.  wink

Awesome! Thanks! (*Whistles* "I knew those guys were quick").  smile

And javascript is not the best way to store passwords, because anyone can simply view the source and get around it.


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#5 2012-05-28 12:56:45

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: A Javascript problem... Yet again (x2)

SJRCS_011 wrote:

PullJosh wrote:

Hardmath123 wrote:

document.getElementById('Pass').value will work

getElementById just returns the element itself, you then need to ask for its value.

P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.  wink

Awesome! Thanks! (*Whistles* "I knew those guys were quick").  smile

And javascript is not the best way to store passwords, because anyone can simply view the source and get around it.

If you use ajax, you can use a php script to echo a password, but only if the current url isnt where the php script is. That way, nobody can view the password. However, i can think of a few ways to get around this, too.


I am currently http://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=imagehttp://blocks.scratchr.org/API.php?user=GP1&amp;action=onlineStatus&amp;type=text and I finally got over 1000 posts.

Offline

 

#6 2012-05-28 13:06:14

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: A Javascript problem... Yet again (x2)

PullJosh wrote:

Hardmath123 wrote:

document.getElementById('Pass').value will work

getElementById just returns the element itself, you then need to ask for its value.

P.S. You should use onclick="action()" rather than javascript:action(). Also, use the <html><head><body> syntax to keep your code clean, and put in type="text/javascript" in your script definitions.  wink

Awesome! Thanks! (*Whistles* "I knew those guys were quick").  smile

You're welcome.  smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7 2012-05-28 14:37:20

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: A Javascript problem... Yet again (x2)

Yeah, don't store your passwords with Javascript!  tongue  Use PHP which will keep it hidden from viewers  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2012-05-28 16:10:22

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

Re: A Javascript problem... Yet again (x2)

sparks wrote:

Yeah, don't store your passwords with Javascript!  tongue  Use PHP which will keep it hidden from viewers  smile

Yeah. It's for some average fourth-graders, though. I don't think the average fourth-grader knows that.  smile


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

 

#9 2012-05-28 16:32:36

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: A Javascript problem... Yet again (x2)

Closed by request of the project owner  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer