please help with JavaScript Form !

O

Olly

Hello Everyone!

Could someone please have a look at my JS Form I posted
below....Something wrong there, but I don't understand what's exactly.

Many thanks.
Olly

===============================
<script language="JavaScript">

function checkChars(field, fieldName) {

var okchars =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.-"
var ok = "yes";
var temp;

for (var i = 0; i < field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (okchars.indexOf(temp) == "-1") ok = "no";
}

if (ok == "no") {
alert("The " + fieldName + " field must contain only alphabetic or
numeric characters, please check for invalid characters.");
field.focus();
field.select();

}

}

function valForm2(theForm){
var ps = document.Form2.single_pw.value;

var theAction = "http://vubiz.com/default.asp?vcust=CCHS2544&vId=" +
ps +
"&vSource=http://ccohs.ca/products/coursesNew/loginnewforall.html";
document.Form2.target = "_blank";
history.go(0);
if (ps == "") {
alert("Please enter your password.");
document.Form2.single_pw.focus();
}
else {
document.Form2.action = theAction;
document.Form2.submit();
}
}

function valForm3(theForm){
var mps = document.Form3.multi_pw.value;
var custID = document.Form3.Cust.value;

var theAction = "http://vubiz.com/v5/default.asp?vCust=" + mps +
"&vId=" + custID + "&vLang=EN" +
"&vSource=http://ccohs.ca/products/coursesNew/loginnewforall.html";
document.Form3.target = "_blank";
history.go(0);

if (mps == "") {
alert("Please enter your password.");
document.Form3.multi_pw.focus();
}
else if (Cust == "") {
alert("Please enter your Customer ID.");
}
else {
document.Form3.action = theAction;
document.Form3.submit();
}

}

</script>
=================


<div align="center">

<table border="0" cellpadding="10" cellspacing="0" width="60%">
<TR>
<TD ALIGN="left" class="bodytext" colspan="3"><strong>Single User
Login :</strong></TD>
</TR>
<TR><form name="Form2" action="javascript:valForm2('Form2');"
method="post">
<TD ALIGN="center" class="bodytext">Password:</TD>
<TD ALIGN="left"><input type="password" name="single_pw" size="10"
onBlur="checkChars(this, 'Password');">
</TD>

<TD ALIGN="left"><input type="image" src="/images/login_on_grey.gif"
width="75" height="17" border="0" value="Link to Login page"
alt="Login"></TD>
</TR>
<TR>
<TD>&nbsp;</TD>
</TR>
</form>
<form name="Form3" action="javascript:valForm3('Form3');"
method="post">
<TR>
<TD ALIGN="left" class="bodytext" colspan="3"><strong>Multi User
License Login :</strong></TD>

</TR>
<TR>
<TD ALIGN="center" class="bodytext">Customer ID:</TD>
<TD ALIGN="left"><input type="text" name="Cust" size="10">
</TD>
<TD ALIGN="left">&nbsp;</TD>
</TR>
<TR>

<TD ALIGN="center" class="bodytext">Password:</TD>
<TD ALIGN="left"><input type="password" name="multi_pw" size="10"
onBlur="checkChars(this, 'Password');">
</TD>
<TD ALIGN="left"><input type="image" src="/images/login_on_grey.gif"
width="75" height="17" border="0" value="Link to Login page"
alt="Login"></TD>
</TR>
<TR>
<TD>&nbsp;</TD>
</TR>

</form>

</table>


</div>
 
O

Olly

Hi Andy:

Thanks for answering my call for help. :)
It would help if you included some information about what's wrong. E.g.
say what's supposed to happen and say what does happen instead. and/or use
your browser's javascript debugging capabilities to report any errors in
the page. (In firefox 1.5 it's tools -> Javascript console)

This is Login page with three text fields in it - Password for Single
User, Password for Multi User and Customer ID for Multi-User, and two
Login buttons (for Single Users and Multi Users). I use two separate
forms on that page (one for Single Users, another - for Multi Users).
Once users click on any of the Login buttons, they're redirected to
external web site.
All three text fields are mandatory, but for some reason function
responsible for Multi Users mandatory fields (Password and Customer ID)
is not working properly. When I troubleshooted this page in Firefox, I
got message saying that my form for Multi Users is not defined. I
suspect, something wrong with my "if, else if" part of the Multi Users
script where I check if users filled in Multi Users fields.

Hope this info was more helpful.

Again, I appreciate your willingness to get me out of that mud.

Regards,
Olly





Andy said:
Olly said:
Hello Everyone!

Could someone please have a look at my JS Form I posted
below....Something wrong there, but I don't understand what's exactly.

Many thanks.
Olly

It would help if you included some information about what's wrong. E.g.
say what's supposed to happen and say what does happen instead. and/or use
your browser's javascript debugging capabilities to report any errors in
the page. (In firefox 1.5 it's tools -> Javascript console)

--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with
HTML:
 or [attachment] in the subject line.[/QUOTE]
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Fri, 2 Jun 2006 14:10:42 remote, seen in
news:comp.lang.javascript said:
<script language="JavaScript">
Deprecated.

function checkChars(field, fieldName) {

var okchars =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.-"
var ok = "yes";
var temp;

for (var i = 0; i < field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);

Consider method charAt.
if (okchars.indexOf(temp) == "-1") ok = "no";
}

if (ok == "no") {
alert("The " + fieldName + " field must contain only alphabetic or
numeric characters, please check for invalid characters.");
field.focus();
field.select();

}

}

Consider
var BAD = /[^[email protected]]/i.test(field.value) // by RegExp
if (BAD) { ...

Code should not be allowed to be wrapped by your posting agent; code as
displayed to us should be both executable and readable.

Avoid naive "validation" of E-addresses.

Read the newsgroup FAQ.
 
O

Olly

Thanks Andy and John!

Here's URL for this page.
http://ccohs.ca/products/coursesNew/mylogin.html

I opened Firfox's JS console and got not error messages.The first form
seems to be working fine, but not the second one. I suspect something
wrong with the conditionals in the second form....

Regards.
Olly



Andy said:
Olly said:
Hi Andy:

Thanks for answering my call for help. :)


This is Login page with three text fields in it - Password for Single
User, Password for Multi User and Customer ID for Multi-User, and two
Login buttons (for Single Users and Multi Users). I use two separate
forms on that page (one for Single Users, another - for Multi Users).
Once users click on any of the Login buttons, they're redirected to
external web site.
All three text fields are mandatory, but for some reason function
responsible for Multi Users mandatory fields (Password and Customer ID)
is not working properly. When I troubleshooted this page in Firefox, I
got message saying that my form for Multi Users is not defined. I
suspect, something wrong with my "if, else if" part of the Multi Users
script where I check if users filled in Multi Users fields.

Hope this info was more helpful.

Again, I appreciate your willingness to get me out of that mud.

Regards,
Olly

Could you say what the exact error message was? Also, does the page work
in IE6? And does the first form work OK? I think (someone correct me
if I'm wrong) that the syntax you are using for getting at the form
element (document.Form3.) is a peculiarity of internet explorer, and isn't
widely supported. So maybe try using:

var form3=null;
var multiPw=null;
if (document.getElementById) {
form3=document.getElementById("form3");
multiPw=document.getElementById("multi_pw");
}
Form3.target = "_blank";
.....
multi_pw.focus()


... etcetera



--
http://www.niftybits.ukfsn.org/

remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with
HTML:
 or [attachment] in the subject line.[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top