javascript autotab and error checking

i have a form with some required fields.  If the field is blank the pages pops up a warning.  It works fine on "normal" fields.
if(document.send_request.city.value==''){
		alert('Please enter city');
		document.send_request.city.focus();
		return false;

Open in new window


On some fields I have an autotab function.
<script language="javascript" type="text/javascript">
			  for(var l=0; l<=2; l++){
			  	var l1=l+1;
				  document.write('<input name="cvv_'+l+'" type="text" class="middletextfield" id="cvv_'+l+'" style="width:10px;" maxlength="1" onKeyup="autotab(this, document.send_request.cvv_'+l1+')"/>');
			  }/*send_request*/
			  </script>

Open in new window


my problem is the error checking doesnt work for fields that have the autotab.

What am I doing wrong?  

What does this line actually do
var l1=l+1;

Open in new window

LVL 1
livegirlloveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
One thing it does is produce a visually confusing line of code!  I wish people would understand that so many errors and annoyances and timewasters can be avoided if you just omit the visually ambiguous letters and numbers from your variable names*.  The list is pretty simple: O (oh), 0 (zero) I (eye), 1 (one), l (ell).  In some fonts, 5 (five), S (ess).  In some fonts, 2 (two), Z (zee).

Taken by itself, the line of code uses the current value of l (ell) and adds one to it.  Then it assigns the resulting value to l1 (ell, one).  All by itself this is not too dramatic, but if you look at the line before it, you will see that it is a for() loop iterator that initially sets l (ell) to zero.  So this l1 (ell, one) variable is a pointer that looks ahead of the current value of the iterator.

* Omit these letters from your passwords, too.  Especially the auto-generated passwords.  And omit them from CAPTCHA images.  They're more trouble than they're worth!
0
duncanb7Commented:
You need to set name attribute in the form, take a look as following code and its autotab function. I put javascript code  for input tag  between form tag, and variable "ll+1" is for the variable in autotab() function  so that you keyup on first input tab and the next input tab
will be focus , so it is ll+1;  1 means next input tag
Try input something in input box 1 and keyup and then you  will see next input box will be focused that is function of autotab

You can use browser developer tools click options->developer tolls->console, or Element, you can see all final code and its error.

Duncan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AutoTab Javascript</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function autotab(current,to){
if (current.getAttribute &&  current.value.length==current.getAttribute("maxlength")) {
        to.focus() 
}
}
</script>
	<body style="width:1000px; height:1000px">
	<form name="send_request">
	<textarea>
	This is testing
	</textarea>
			<script type="text/javascript">
	  for(var l=0; l<=2; l++){
			  	var l1=l+1;
				  document.write('<input name="cvv_'+l+'" type="text" class="middletextfield" id="cvv_'+l+'" style="width:10px;" maxlength="1" onKeyup="autotab(this, document.send_request.cvv_'+l1+')"/>');
			  }/*send_request*/	
			  </script>
	</form>
	
  </body>
</html>

Open in new window

0
livegirlloveAuthor Commented:
if(document.send_request.cvv.value==''){
		alert('Please enter cvv);
		document.send_request.cvv.focus();
		return false;

Open in new window


this doesn't work.
what variable is it seeing.  When I post the form the variable is $cvv but the javascript doesn't seem to be seeing that.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

duncanb7Commented:
try review my previous post and try  my example code , and you will know it,

 where is your autotab funnction?
0
livegirlloveAuthor Commented:
I attached the file.  The autotabs are inline in the form.

The error check is in the header and does the check on submit and pops up a warning message.  I don't want to rewrite this ancient terrible code I just need to know what variable I should have document.send_request.cvv.value?  

document.send_request.cvv+ll+.value
document.send_request.cvv_.value
document.send_request.cvv+i+.value


thanks
page08.html
0
duncanb7Commented:
I run your page that is working, I type 1 at box 1on cvv, it will go and focus to next box, so on
the autotab function is okay no error.

Where is error area you are talking ?  I don't find any error and review your question post that
is not mentioned.

You need to write it in detail ,otherwise confusing

Duncan
0
livegirlloveAuthor Commented:
the auto tab works.  If you enter nothing in the cvv box it should popup  a warning message.  It does not popup the message and allows the form to submit.

If you don't enter phone number the warning works correctly.
auto tab works.  error checking does not but only on fields that use autotab.  credit card and cvv
0
duncanb7Commented:
Is it what you want for check() ? other check for input is similar
if(document.send_request.cvv_0.value==''){
		alert('Please enter cvv');
		document.send_request.city.focus();
		return false;
}
if(document.send_request.cvv_1.value==''){
		alert('Please enter cvv');
		document.send_request.city.focus();
		return false;
}
if(document.send_request.cvv_2.value==''){
		alert('Please enter cvv');
		document.send_request.city.focus();
		return false;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
livegirlloveAuthor Commented:
that works perfect thanks
0
livegirlloveAuthor Commented:
you are correct its wrong.  but the point was I need cvv_0 etc.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.