473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

not sure what is stopping my code from running

i broke down where i think the problems areas would be.
any help would be greatly appreciated.

where the file is called
<script type="text/javascript" src="k.js">
</script>
the beginning of my form, test.cgi doesnt exsist but i think it should
run the function before the action. Is this correct???
<form name="courseform" action="test.cgi" method="post"
onsubmit="return checkForm(this);">

then my code in the file

not sure if it would be better to do the getElementById or just
theform.last_name.value
I havent finished the script but i think you get the idea.

i know the long number are a bit off the wall but i have to use them
sadly.

well thank you for looking over my code.
brian
<script>

function checkForm(theForm)
{
alert("yes");
var error = "";
error += checkFname(theForm..getElementById('first_name').v alue);
error += checkLname(theForm.last_name.value);
error += checkPhone(theForm.phone.value);
error += checkEmail(theForm.email.value);
error += checkCntmethod(theForm.00N40000001U1MW.selectedInd ex);
error += checkCnttime(theForm.00N40000001U1Mm.value);
error += checkAgency(theForm.company.value);
error += checkAtype(theForm.00N40000001U1MR.selectedIndex);
error += checkAaddress(theForm.street.value);
error += checkAcity(theForm.city.value);
error += checkAcounty(theForm.00N30000001E9CN.value);
error += checkAzip(theForm.zip.value);
error += checkCrsname(theForm.00N40000001U1MN.selectedIndex );
error += checklanguage(theForm.00N40000001U2Z8.selectedInde x);
error += checkPdate(theForm.00N40000001U1Mx.value);
error += checkPtime(theForm.00N40000001U1NF.selectedIndex);
error += checkAdate(theForm.00N40000001U1Li.value);
error += checkAtime(theForm.00N40000001U1Lo.selectedIndex);
error += isEmpty(theForm.notempty.value);
error += isDifferent(theForm.different.value);

if (error != "") {
alert(error);
return false;
}
return false;
}

//checks the first name for null statement and length
function checkFname(fname){
var errror = "";
if(fname ==""){
error = "You did not enter a first name. /n"
}
else if (fname.length < 2 || fname.length 15){
error = "The name entered is incorrect. /n"
}
return error;
}

//checks last name for null statement
function checkLname(lname){
var errror = "";
if(lname ==""){
error = "You did not enter a last name. /n"
}
return error;
}

function checkPhone(phone){
var errror = "";
if(phone ==""){
error = "You did not enter a phone number. /n"
}
else if(phone.length == 10){
error = "Your phone number is the incorrect length. /n"
}
return error;
}

function checkEmail(email){
var errror = "";
if(email ==""){
error = "You did not enter an email address. /n"
}
return error;
}

//checks the contact method
function checkCntmethod(choice) {
var error = "";
if (choice == 0) {
error = "You did not choose a Best cotact method.\n";
}
return error;
}

function checkCnttime(conTime){
var errror = "";
if(conTime ==""){
error = "You did not enter a contact time. /n"
}
return error;
}

function checkAgency(agency){
var errror = "";
if(agency ==""){
error = "You did not enter your agency's name. /n"
}
return error;
}

function checkAtype(choice) {
var error = "";
if (choice == 0) {
error = "You did not choose an agency type.\n";
}
return error;
}

function checkAaddress(address){
var errror = "";
if(adress ==""){
error = "You did not enter the agency's address. /n"
}
return error;
}

function checkAcity(city){
var errror = "";
if(city ==""){
error = "You did not enter the agency's city. /n"
}
return error;
}

function checkAcounty(county){
var errror = "";
if(county ==""){
error = "You did not enter the agency's city. /n"
}
return error;
}
</script>

Oct 24 '06 #1
4 1557

brian wrote:
<script>
In your external javascript file, you do not need the script tag.
function checkForm(theForm)
{
alert("yes");
var error = "";
error += checkFname(theForm..getElementById('first_name').v alue);
There's a typo. You have two '.', but even then, is the
getElementById() method necessary?

[snip]
>
if (error != "") {
alert(error);
return false;
}
return false;
}
This may be problematic. You're saying, if there's a error, alert the
messages and do *not* submit the form. However, at the end you're also
saying, do *not* submit the form. You probably meant to return true at
the end, thus submitting the form to the action that you've placed.

[snip]

Oct 24 '06 #2
web.dev said the following on 10/24/2006 6:32 PM:
brian wrote:
><script>

In your external javascript file, you do not need the script tag.
>function checkForm(theForm)
{
alert("yes");
var error = "";
error += checkFname(theForm..getElementById('first_name').v alue);

There's a typo. You have two '.', but even then, is the
getElementById() method necessary?
It is not only un-necessary but it will throw an error as FORM elements
do not have a method of getElementById - it belongs to the document
alone. Not even the - window - object can use it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 24 '06 #3
ASM
brian a écrit :
the beginning of my form, test.cgi doesnt exsist but i think it should
run the function before the action. Is this correct???
yeap
<form name="courseform" action="test.cgi" method="post"
onsubmit="return checkForm(this);">

then my code in the file

not sure if it would be better to do the getElementById or just
theform.last_name.value
certainly not doing :
checkFname(theForm..getElementById('first_name').v alue);
--------------------^^
only one point please !

Your function checkForm() is out on its first line :-(

Anyway it is always better to address to elements of a form
by the tree of forms :

var elt =document.forms['myForm'].elements['myElement']
or
var elt =document.myForm.myElement
or
var f = document.forms['myForm'];
var elt = f.myElement;

var val = elt.value
<script>

function checkForm(theForm)
{
alert("yes");
var error = "";
error += checkFname(theForm..getElementById('first_name').v alue);
|
here ------------------------------+
error += checkLname(theForm.last_name.value);
(snip
if (error != "") {
alert(error);
return false;
}
return false;
no ! return true; (except if it was for your tests)
}

else if(phone.length == 10){
error = "Your phone number is the incorrect length. /n"
I'm sorry not in France !

and what you do with spaces ?

}
return error;
}

--
ASM
Oct 24 '06 #4
brian wrote:
i broke down where i think the problems areas would be.
any help would be greatly appreciated.
In addition to what others have said:

[...]
function checkForm(theForm)
{
alert("yes");
var error = "";
error += checkFname(theForm..getElementById('first_name').v alue);
error += checkLname(theForm.last_name.value);
error += checkPhone(theForm.phone.value);
The += compound operator is very slow in at least one popular browser,
you may find it quicker to concatenate results:

var error =
checkFname(theForm..getElementById('first_name').v alue)
+ checkLname(theForm.last_name.value)
+ checkEmail(theForm.email.value)
+ ...

error += checkEmail(theForm.email.value);
error += checkCntmethod(theForm.00N40000001U1MW.selectedInd ex);
To be valid, id and name attributes must start with a letter.

[...]
if (error != "") {
alert(error);
Your users may find it more helpful if you write errors to the page,
that way they can still see the message while they fix them. Using an
alert, they have to remember what the errors were - and they may get 20
of them.
return false;
}
return false;
As Steph said, that should be true.
}

//checks the first name for null statement and length
function checkFname(fname){
var errror = "";
if(fname ==""){
error = "You did not enter a first name. /n"
}
Given that the local variable is called 'errror', this will create a
global variable 'error' and give it a value, but only if the function
is called. That may cause unexpected and difficult to find problems
elsewhere.

You have multiple instances of this error. It can be avoided by
removing the local 'error' variable and just returning the message:

function checkFname(fname) {
if (fname =="") {
return "You did not enter a first name. /n"
} else if (fname.length < 2 || fname.length 15){
return "The name entered is incorrect. /n"
}
}

The advice returned by the else branch doesn't seem to fit the test,
you should say something like "First name must be from 2 to 15
characters inclusive".

//checks last name for null statement
It checks to see if the value is an empty string - null is a special
value in javascript.
function checkLname(lname){
var errror = "";
if(lname ==""){
error = "You did not enter a last name. /n"
}
return error;
}
[...]
function checkAcounty(county){
var errror = "";
if(county ==""){
error = "You did not enter the agency's city. /n"
Or maybe the county?
There may be other errors...

--
Rob

Oct 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matteo | last post by:
Hi everyboby, i wrote a c# service that every XXX minute launch a working thread on timer events, something like this: private void timer_Elapsed ( object status ) { // Worker thread...
5
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an...
1
by: mclaugb | last post by:
Here is a simple piece of thread code. When i add the print (or other) function into the run method--the thread fails to stop after 2 seconds which the join(2) should ensure. I have a function...
4
by: bjm | last post by:
I am writing a program that will automate a series of application installations. I want to give the user the option of stopping the program's execution in between installations (for example, give...
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello everyone, I have this application that stops and starts IIS admin. When I try to stop the service. I get an error "Cannot open IISADMIN service on computer '.'.". I tried changing the...
6
by: blaine | last post by:
Hello, I'm currently overriding function keys (F1 to F4) to perform other actions. In order to do this the default popup windows of Help (F1), Seach(F3) etc must be turned off. In FF it's easy...
10
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on...
4
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.