Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Need help creating a counter that keeps count from differant functions

so I need yo keep a counter from different functions like this

 $(document).ready(function(){

showButton = 0;
 $("#subButton").hide();
 
 
 $('#field1).bind("keyup blur",function() {
if( somthing )) {
$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-no.png" width="15" height="15" /></sub></span>');
}else{
$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-yes.png" width="15" height="15" /></sub></span>');
showButton = showButton + 1
}});

 $('#field2).bind("keyup blur",function() {

if( somthing2 )) {
$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-no.png" width="15" height="15" /></sub></span>');
}else{
$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-yes.png" width="15" height="15" /></sub></span>');

showButton = showButton + 1
}
});



$(function() {
if(fields_email == 2) {

$('#subButton').show();
}
});
 
 });
0
gvilla23
Asked:
gvilla23
  • 5
  • 3
1 Solution
 
gvilla23Author Commented:
Sorry the last part should be

$(function() {
if(showButton  == 2) {

$('#subButton').show();
0
 
leakim971PluritechnicianCommented:
Put "var showButton = 0;" before $(document).ready(function(){
var showButton = 0; // added here
 
$(document).ready(function(){
// removed from here
 $("#subButton").hide();

Open in new window

0
 
gvilla23Author Commented:
Did not work....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leakim971PluritechnicianCommented:
could you post your current code?
0
 
leakim971PluritechnicianCommented:
Because I saw some typo errors in your code :
var showButton = 0;

	$(document).ready(function(){

		$("#subButton").hide(); 
		
		$('#field1').bind("keyup blur",function() { 
			if( somthing ) {
				$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-no.png" width="15" height="15" /></sub></span>');
			} else {
				$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-yes.png" width="15" height="15" /></sub></span>');
				showButton = showButton + 1
			}
		});
				
		$('#field2').bind("keyup blur",function() { 
				
			if( somthing2 ) {
				$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-no.png" width="15" height="15" /></sub></span>');
			} else {
				$(this).after('&nbsp; <span class="error error-fname"><sub><img src="images/check-mark-yes.png" width="15" height="15" /></sub></span>');
				showButton = showButton + 1
			}
		});
				
		$(function() {
			if(fields_email == 2) {
				$('#subButton').show();
			}
		});
	
	});

Open in new window

0
 
gvilla23Author Commented:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
 <script type='text/javascript'>


      $(document).ready(function(){
var showButton = 1;
            $("#subButton").hide();
            
            $('#field1').bind("keyup blur",function() {
                  ///if( somthing ) {
                         if ($(this).val() ==" "){
                        $(this).after('hello');
                  } else {
                        $(this).after('good bye');
                        showButton ++;
                  }
            });
                        
            $('#field2').bind("keyup blur",function() {
                        
                         if ($(this).val() ==" "){
                        $(this).after('hello');
                  } else {
                        $(this).after('good bye');
                        showButton ++;
                  }
            });
                        
            $(function() {
                  if(showButton == 3) {
                        //$('#subButton').show();
                        alert("WTF")
                  }
            });
      
      });

</script>

</head>

<body>


<input  type='text' id='field1' name='fields_fname1' /><br>
<input  type='text' id='field2' name='fields_fname2' />


</body>
</html>
0
 
leakim971PluritechnicianCommented:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
 <script type='text/javascript'>
	var showButton = 1;

	$(document).ready(function(){
		$("#subButton").hide(); 
		
		$('#field1').bind("keyup blur",function() { 
			///if( somthing ) {
			if ($(this).val() ==" "){
				$(this).after('hello');
			} else {
				$(this).after('good bye');
				showButton ++;
			}
			checkShowButton();
		});
		
		$('#field2').bind("keyup blur",function() { 
		
			if ($(this).val() ==" "){
				$(this).after('hello');
			} else {
				$(this).after('good bye');
				showButton ++;
			}
			checkShowButton();
		});
		
		function checkShowButton() {
			if(showButton == 3) {
				//$('#subButton').show();
				alert("WTF")
			}
		}
	
	});

</script>
</head>
<body>
<input  type='text' id='field1' name='fields_fname1' /><br>
<input  type='text' id='field2' name='fields_fname2' />
</body>
</html>

Open in new window

0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now