Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple password validation script not working in IE

Status
Not open for further replies.

smitheroo

Programmer
Aug 30, 2008
15
0
0
GB
Hi,

Please can someone cast an experienced javascript eye over this code?

I've got this simple validation demo to work in Firefox by entering some stored content into two text fields and hitting enter it goes to the next demo page. I can't see what I need to amend to get it to work in IE. I've tried experimenting for hours and hours but I'm guessing it's to do with the 'onchange' event handler, but I'm no expert.

Any clues?

thanks...

(note - I can't use a visible submit button)

<code>
<script language="javascript">
<!--//
function pasuser(form) {
if (form.cmsorg.value=="120") {
if (form.cardnumber.value=="377064291003232") {
location="step2.html"
} else {
alert("Incorrect Card number entered. Please enter the correct number")
}
} else { alert("Incorrect CMS ORG number entered. Please enter the correct number")
}
}
//-->
</script>
</code>


<code>
<form name="login">

<input style="position:relative; top:162px; left:128px; width:40px; float:left; background-color:#000; color:#00FFCC; font-size:110%; border:0px solid #fff;" tabindex="1" name="cmsorg" type="text">

<input style="position:relative; top:161px; left:292px; width:200px; background-color:#000; color:#00FFCC; font-size:110%; border:0px solid #fff;" tabindex="2" name="cardnumber" type="text" onChange="pasuser(this.form)">

</form>
</code>

 
Hi

Note that "hitting enter", as you mentioned, and handling [tt]onchange[/tt] event, as you did, is not the same.

Pressing Enter on a control which not handles Enter presses itself usually submits the [tt]form[/tt]. So try moving the pasuser() call :
Code:
<form name="login" [red]onsubmit="pasuser(this); return false"[/red]>
By the way, I hope that your example is just a joke and in reality you are not doing such validations. Or at least you are validating later again on server side.

Feherke.
 
Many thanks for the quick response and help, much appreciated.

I've moved the pasuser call, it doesn't work in IE of FF now.

<code>
<form name="login" onsubmit="pasuser(this); return false">

<input style="position:relative; top:162px; left:128px; width:40px; float:left; background-color:#000; color:#00FFCC; font-size:110%; border:0px solid #fff;" tabindex="1" name="cmsorg" type="text">

<input style="position:relative; top:161px; left:292px; width:200px; background-color:#000; color:#00FFCC; font-size:110%; border:0px solid #fff;" tabindex="2" name="cardnumber" type="text">

</form>
</code>


2 questions:

Do I need a hidden submit button?

Do I need to amend the function name to pasuser() instead of pasuser(form), I don't really understand the difference.

Many thanks
 
Hi

smitheroo said:
Do I need a hidden submit button?
Oops, forgot that. Yes, you need a [tt]submit[/tt] button anywhere in that [tt]form[/tt].
smitheroo said:
Do I need to amend the function name to pasuser() instead of pasuser(form), I don't really understand the difference.
No. If you are not passing the reference to the [tt]form[/tt] to process then you will need to reach its elements as [tt]document.login.cmsorg[/tt] or [tt]document.forms['login'].elements['cmsorg'][/tt] or by [tt]id[/tt] if you give them. So better leave it as is, passing the reference as parameter.

Feherke.
 
Hello,

You're correct well done! just needed a hidden submit button in there too. I really appreciate your help.

:~]


 
Sorry to hijack but I am working on something similiar ..
But for my version I am looking to have it only operate 3 times and then redirect to another page.

I tried using a do-while loop, but am coming from c and am a little uncertain.

code is below

-------------------
<script language="javascript">

function pincode(form) {
var tick = 0;


if ( tick <= 3 ) {
if (form.pincode.value=="1432")
{
location="step2.html";
}
else
{
alert("Incorrect Pincode. Try again.");
location="error.html";
}
tick++;
}
else
{
alert("Incorr.");
}


</script>

</head>

<body>


<form name="login" onsubmit="return pincode(this)">

<input style="position:absolute; top:140px; left:560px; width:100px; background-color:#000000; color:#ffffff; font-size:100%; border:0px solid #fff;" tabindex="1" name="pincode" type="text" onChange="pincode(this.form)">
<br>
<input style="position:absolute; top:160px; left:580px;" type="submit" value="Submit">

</form>
---------------
 
Sorry to hijack but I am working on something similiar ..
But for my version I am looking to have it only operate 3 times and then redirect to another page.

I tried using a do-while loop, but am coming from c and am a little uncertain.

code is below

-------------------
<script language="javascript">

function pincode(form) {
var tick = 0;


if ( tick <= 3 ) {
if (form.pincode.value=="1432")
{
location="main.html";
}
else
{
alert("Incorrect Pincode. Try again.");
location="error.html";
}
tick++;
}
else
{
alert("Incorr.");
}


</script>

</head>

<body>


<form name="login" onsubmit="return pincode(this)">

<input style="position:absolute; top:140px; left:560px; width:100px; background-color:#000000; color:#ffffff; font-size:100%; border:0px solid #fff;" tabindex="1" name="pincode" type="text" onChange="pincode(this.form)">
<br>
<input style="position:absolute; top:160px; left:580px;" type="submit" value="Submit">

</form>
---------------
 
Hi

Please forget all that.

If the user can simply view the source code and read the correct value, why would fail more than 3 times to copy & paste it ?

Feherke.
 
True ..but its just an exercise feherke.. not commerical.. just trying to get to grips with java script integration with html really.

My main issue is that my do-while loop doesn't seem to function nor does my if statement, if I use nesting.
 
Hi

Declare the tick variable outside the [tt]function[/tt]. Now it is a local variable, so its life ends when the [tt]function[/tt] terminates and whatever you set, vanishes.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top