Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Script Help

  Asked By: Thelma    Date: Mar 30    Category: Java    Views: 655
  

I have made the following script to validate a username and password
for entry to a secured site but can't seem to get it to work properly

<script language = "javascript">

/*
*/

function validate(text1,text2,text3,text4)
{
if (text1=1111=text2 && text3=dummy=text4)
load('Latrobe.mdb');
else
{
load('failure.htm');
}
}
function load(url)
{
location.href=url;
}
</script>



<-----Text 1 is the password text 2 is the username----->

<------ Here is the form------>

<form>
<p>ENTER USER NAME :
<input type="text" name="text2">
</p>
<p> ENTER PASSWORD :
<input type="password" name="text1">
<input type="button" value="Check In" name="Submit"
onclick=javascript:validate
(text2.value,"free",text1.value,"javascript") >
</p>

</form>

Is the data being entered in the wrong areas?
I believe the if function is formatted wrong?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Frederick Greene     Answered On: Mar 30

I am not a javaScript guy but I think you need to use double
equals "==" when testing for a condition. so instead of saying:
text3=dummy, you need to use text3==dummy

also I don't think you can test if three things are equal at the
same time i.e. instead of:

text3=dummy=text4

use:
(text3==dummy)&&(dummy==text4)

note: dummy needs to exist as a global String variable or a one
declared in your function.

also 1111 should be "1111" if you need to compare it with a String.

I am not sure about all the points here, but have a look on the
Internet for how to use if statements in JavaScript, I'm sure you'll
find a lot of material!!

 
Answer #2    Answered By: Kelly Bell     Answered On: Mar 30

I just used 1111 as the example password  and Dummy as the username.
I'm not sure I really need 3&4 as 1&2 are the username and password!

 
Answer #3    Answered By: Angel Harris     Answered On: Mar 30

Put the following in the head section of the web page (after the <head> and
before the </head> tag

<script language = "javascript">

/*
*/

function validate(text1,text2,text3,text4)
{
if ((text1="1111")
&& (text2=="1111")
&& (text3=="dummy")
&& (text4 =="dummy"))
load('Latrobe.mdb');
else
{
load('failure.htm');
}
}
function load(url)
{
location.href=url;
}
</script>

The form portion goes into the body section of the web page.
between <body>
and
</body>

 
Didn't find what you were looking for? Find more on Script Help Or get search suggestion and latest updates.




Tagged: