Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > please help with JavaScript Form !

Reply
Thread Tools

please help with JavaScript Form !

 
 
Olly
Guest
Posts: n/a
 
      06-02-2006
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 =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM NOPQRSTUVWXYZ@.-"
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>

 
Reply With Quote
 
 
 
 
Olly
Guest
Posts: n/a
 
      06-03-2006
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 Baxter wrote:
> 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.


 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      06-03-2006
JRS: In article < om>,
dated Fri, 2 Jun 2006 14:10:42 remote, seen in
news:comp.lang.javascript, Olly <> posted :

><script language="JavaScript">


Deprecated.

>function checkChars(field, fieldName) {
>
> var okchars =
>"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL MNOPQRSTUVWXYZ@.-"
> 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 = /[^a-z0-9@.-]/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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Olly
Guest
Posts: n/a
 
      06-05-2006
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 Baxter wrote:
> Olly said:
>
> > 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

>
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need your help, I am new with javascript, what do I wrong? javascript form validation suddenly doesn´t work francisco lopez Javascript 2 12-30-2004 12:18 PM
Smiley Click picker using Javascript and FORM woes .. Please help... descds Javascript 3 09-16-2004 06:30 AM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM
Please help me with a simple javascript form minstrel80232 Javascript 1 10-03-2003 08:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57