You are viewing limited content. For full access, please sign in.

Question

Question

Javascript to match Email fields

asked on June 1, 2017

I am trying to use Java to match an email address entered in two fields. Once the email addresses are the same in both fields, I need the Submit button to show.

$(document).ready(function() {
  $('.Submit').hide();
  $('#q6 input').on('blur change', function() {
    if ($('#q6 input').val() = $('#q7 input').val()) {
      $('.Submit').show();
    } else {
      $('.Submit').hide();
    }
  });
});

1 0

Answer

SELECTED ANSWER
replied on June 13, 2017 Show version history

Here you go!

$(document).ready(function(){
  
  	if(($('#q10 input').val()=='') && ($('#q9 input').val()=='')){
      $('input[type="submit"]').hide();
  	}
      $('#q9 input').on('change', function(){
        var currentvalue = $(this).val();
        $(this).val(currentvalue.toLowerCase());
      	if($('#q9 input').val() == $('#q10 input').val()){
		 	$('input[type="submit"]').show();
        }
        if($('#q9 input').val() !== $('#q10 input').val()){
			$('input[type="submit"]').hide();
        }
      });
      $('#q10 input').on('change', function(){
        var currentvalue = $(this).val();
        $(this).val(currentvalue.toLowerCase());
        if($('#q10 input').val() == $('#q9 input').val()){
			$('input[type="submit"]').show();
        }
        if($('#q10 input').val() !== $('#q9 input').val()){
			$('input[type="submit"]').hide();
        }
      });                  
});

 

1 0

Replies

replied on June 2, 2017 Show version history

Hi I was able to get this working using below. The logic is very similar to yours. 

#q9 and #q10 are id's of the email fields. I just took into consideration for initial situation where both fields are blank and the order in which the user fields in the fields.


$(document).ready(function(){
  	if(($('#q10 input').val()=='') && ($('#q9 input').val()=='')){
           $('input[type="submit"]').hide();
  	}
        $('#q9 input').on('change', function(){
      	  if($('#q9 input').val() == $('#q10 input').val()){
		 	$('input[type="submit"]').show();
          }
          if($('#q9 input').val() !== $('#q10 input').val()){
			$('input[type="submit"]').hide();
          }
        });
        $('#q10 input').on('change', function(){
          if($('#q10 input').val() == $('#q9 input').val()){
			$('input[type="submit"]').show();
          }
          if($('#q10 input').val() !== $('#q9 input').val()){
			$('input[type="submit"]').hide();
          }
        });                  
});

Rather than hiding, you can also disable the buttons by using something like below:

$("#buttonActivate").prop("disabled", false);
1 0
replied on June 11, 2017

@████████, would it be possible to change this a little bit more so that both email fields are forced to lower case?  I found that if a user types in their email address correctly but one has a capital and the other doesn't, it doesn't match.

 

Thanks in advance

0 0
SELECTED ANSWER
replied on June 13, 2017 Show version history

Here you go!

$(document).ready(function(){
  
  	if(($('#q10 input').val()=='') && ($('#q9 input').val()=='')){
      $('input[type="submit"]').hide();
  	}
      $('#q9 input').on('change', function(){
        var currentvalue = $(this).val();
        $(this).val(currentvalue.toLowerCase());
      	if($('#q9 input').val() == $('#q10 input').val()){
		 	$('input[type="submit"]').show();
        }
        if($('#q9 input').val() !== $('#q10 input').val()){
			$('input[type="submit"]').hide();
        }
      });
      $('#q10 input').on('change', function(){
        var currentvalue = $(this).val();
        $(this).val(currentvalue.toLowerCase());
        if($('#q10 input').val() == $('#q9 input').val()){
			$('input[type="submit"]').show();
        }
        if($('#q10 input').val() !== $('#q9 input').val()){
			$('input[type="submit"]').hide();
        }
      });                  
});

 

1 0
replied on June 2, 2017

This post should work for you. The JSFiddle shows a working version, just change it from password to email and you should be good to go.

 

https://stackoverflow.com/questions/12167399/i-need-the-submit-button-to-enable-when-the-passwords-match-jquery

http://jsfiddle.net/965mG/1/  

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.