• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

javascript help

#1
hey it's me again with another programming question,
i have a problem with 2 of my functions:

this function isn't working as it should, it's supposed to fail if the user enters anything other than letters in the name field
i tried the 'isNaN()' function but that did'nt work so i tried doing it manually that didn't work either
Code:
function Field01(){
	if(document.assign3.field01.value==""){
		sErrMsg+="<li> Name field cannot be empty </li>";
		bErrors=true;
	}else if(document.assign3.field01.value.length<2){
		sErrMsg+="<li> Name must contain at least two characters </li>";
		bErrors=true;
	}

	var num=false;
	var pos=document.assign3.field01.value;

	for(i=0;i<=document.assign3.field01.value.length;i++){
		if(pos.charAt(i)>'a') num=true;
		else if(pos.charAt(i)<'z') num=true;
		else if(pos.charAt(i)>'A') num=true;
		else if(pos.charAt(i)<'Z') num=true;
	}
	
	if(num){
		sErrMsg+="<li> Name field must contain letters only </li>";
		bErrors=true;
	}
}
[edit]
ok i got the code below to work it turns out i was supposed to loop i<=5 times only coz i had 5 items only i thought it would work as in C++ and C

but i dont know what's wrong with the code above
[/edit]

this code isn't working, i dont know what's wrong with it?
Code:
function Field04(){
	var check=true;

	for(var i=0;i<6;i++){
		if(document.assign3.field04.options[i].selected){
			check=false;
			break;
		}
	}

	if(check){
		sErrMsg+="<li> Please select an option from the menu list </li>";
		bErrors=true;
	}
}
it's giving me that error
'document.assign3.field04.options[...].selected' is null or not an object
it's for a project due tonight
 
#2
and this function is working backwards, if 1 checkbox is left unchecked it works instead of if 1 checkbox is checked it works
man something must be wrong with all my codes
Code:
function Field05(){
	var check=true;

	for(var i=0;i<6;i++)
		if(document.assign3.element[i].checked==true)
			check=false;

	if(check==true){
		sErrMsg+="<li> Please select one of the check boxes </li>";
		bErrors=true;
	}
}
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies