Link to home
Start Free TrialLog in
Avatar of livegirllove
livegirllove

asked on

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

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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!
Avatar of duncanb7
duncanb7

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

Avatar of livegirllove

ASKER

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.
try review my previous post and try  my example code , and you will know it,

 where is your autotab funnction?
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
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
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
ASKER CERTIFIED SOLUTION
Avatar of duncanb7
duncanb7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that works perfect thanks
you are correct its wrong.  but the point was I need cvv_0 etc.