PDA

View Full Version : Javascript Challange/question


JavalessUser
12-17-2002, 06:53 PM
Okay I want to have a series of buttons of numbers ex:

[1][2][3]
[4][5][6]
[7][8][9]
[0]

and on clicking them it sends to a form the number

ex: onclick btn1=frm.value+="1";onclick btn2=frm.value+="2";

but i also want it to set up where the form has onclick=pass()

where pass() would be a value like "11217". Also want the form value to limit to 5 characters only.
onclick if the var is pass1="11217" alert('Access granted')

but also if the password isnt the pass1 then alert(access denied)


Think it can be done? And if so what would the code me?

Mr J
12-17-2002, 07:08 PM
Something like this?





<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script>
pwd=12345
function pass(n){
if(document.f1.t1.value.length==5){return}
document.f1.t1.value+=n
if(document.f1.t1.value.length==5){
if(document.f1.t1.value==pwd){
alert("Access Granted")
}
else{
alert("Access denied")
}
}
}
</script>
</HEAD>
<BODY>
<form name=f1>
<input type=button name=b1 value=1 onclick="pass(1)">
<input type=button name=b2 value=2 onclick="pass(2)">
<input type=button name=b3 value=3 onclick="pass(3)"><BR>
<input type=button name=b4 value=4 onclick="pass(4)">
<input type=button name=b5 value=5 onclick="pass(5)">
<input type=button name=b6 value=6 onclick="pass(6)"><BR>
<input type=button name=b7 value=7 onclick="pass(7)">
<input type=button name=b8 value=8 onclick="pass(8)">
<input type=button name=b9 value=9 onclick="pass(9)"><BR>
<input type=button name=b0 value=0 onclick="pass(0)"><BR>
<input type=text name=t1 size=5 maxlength=5><BR>
<input type=reset>
</form>
</BODY>
</HTML>

JavalessUser
12-17-2002, 07:29 PM
Similar but where you would have to click an enter button to go forward

Borgtex
12-17-2002, 07:49 PM
Well, just add another button to check it instead of doing it when you complete the sequence. Or you where asking for somebody to write all the code for you?

Mr J
12-17-2002, 07:54 PM
This will go automatically when correct number enter .. or do you want a button?

<script>
pwd=12345
function pass(n){
if(document.f1.t1.value.length==5){return}
document.f1.t1.value+=n
if(document.f1.t1.value.length==5){
if(document.f1.t1.value==pwd){
alert("OK")
location="YOURPAGE.html"
}
else{
alert("BAD")
}
}
}
</script>




WITH a button


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script>
pwd=12345
function pass(n){
if(document.f1.t1.value.length==5){return}
document.f1.t1.value+=n
if(document.f1.t1.value.length==5){
if(document.f1.t1.value==pwd){
alert("Access Granted")
document.f1.going.disabled=false
}
else{
alert("Access Denied")
}
}
}

function where(){
location="YOURPAGE.html"
}


</script>
</HEAD>
<BODY>
<form name=f1>
<input type=button name=b1 value=1 onclick="pass(1)">
<input type=button name=b2 value=2 onclick="pass(2)">
<input type=button name=b3 value=3 onclick="pass(3)"><BR>
<input type=button name=b4 value=4 onclick="pass(4)">
<input type=button name=b5 value=5 onclick="pass(5)">
<input type=button name=b6 value=6 onclick="pass(6)"><BR>
<input type=button name=b7 value=7 onclick="pass(7)">
<input type=button name=b8 value=8 onclick="pass(8)">
<input type=button name=b9 value=9 onclick="pass(9)"><BR>
<input type=button name=b0 value=0 onclick="pass(0)"><BR>
<input type=text name=t1 size=5 maxlength=5><BR>
<input type=reset>
<input type=button name=going value="Go" onclick="where()" disabled>
</form>
</BODY>
</HTML>

JavalessUser
12-17-2002, 09:17 PM
I want the button rather then automatic *so it simulates an electronic code door better* Thank you also for helping me on this.

whammy
12-18-2002, 01:45 AM
Is this another javascript password scheme? :rolleyes:

These seem really cool when you're new to web programming but they are pointless since you can't truly protect anything client-side with a password. The best you can do is use some method that "ends up" (regarding the script) with someone typing in a page name that doesn't have any links to it otherwise... you can obfuscate it however you want... :D

I'd just rather have someone type in the page name (if you must use javascript), and make it simple because there is no point otherwise.