2 Replies - 3816 Views - Last Post: 29 November 2011 - 07:59 PM

#1 Mohan3088  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 11

Javascript (.jsp) : Captcha validation error message

Posted 28 November 2011 - 10:11 PM

good day experts,

1. Im working on a login module at "forgot password" link.
2. A small window is opened when user clicks"forgot password" link.
3. User need to enter id,email address and the captcha characters appeared before user clicks the "Submit" button.
4. Temporary password is sent to the email if the user entered CORRECT id,email and captcha.
5. Red error message ("Wrong validation code) is appeared below the captcha textfield when the user entered wrong characters in that textfield and the "Submit" button is clicked. *no submission happen here (succeed)
6. I have done all this successfully.
7. Case: I fill in wrong captcha characters and click "Submit", red "Wrong validation code" message is appeared. I click "Close" button of the "forgot password" window and open back the "forgot password" window. I enter wrong captcha characters again and click "Submit". No submission happen here BUT there is no red "Wrong validation code" error message is appeared !!
8. Prob: red error message for wrong captcha characters entered only appear at the first time/ first load user use the "forgot password" window.
9. Ques:How to make the error message "Wrong validation code" appear for the second time and not only for the first time when the user enter wrong captcha characters.. Thank you.. note: no error in the log (console)

-----------------------------------------Two (.jsp) files codes involved(impt part of codes)-----------------
ForgotPassword.jsp file code :

$('#btnSubmitInfo2').button().click(function() {
 	 	if ($('#forgotForm').valid()) {	  
            if ($('#verificationCode1').val() == $('#codeCaptcha').val()) {
        	    var param = { loginId: $('#txtUserId').val(), email: $('#txtEmail').val() }; 
        	    $('#forgotForm').attr("action",blesscontextpath+"/action/registration?forgotPassword");
         		$('#forgotForm').submit();
         	} else {
         	    $('#messageCode2').replaceWith('<p id="messageCode" class="message"><font color="red">Wrong validation code</font></p>');
         	}
  		}      
  		return false;
    });

___________________________________________________________________________________

login.jsp file code:

 $("#dialogForgot").dialog({
	    autoOpen: false,
	    height: 'auto',
	    width: 'auto',
	    modal: true,
	    title:'Forgot Password',

       buttons: {
	        'Close': function() {
	            $('label.error').remove();
	            $('.required').removeClass('error');
	            $('.message').remove();
	            $('.field').val('');
	            $(this).dialog('close');
	        }
	    },
     open: function() { 
	        var temp = bless.randomString(4);
	        $('.fontCaptcha').text(temp);
	        $('#codeCaptcha').val(temp);
    }
    });







Is This A Good Question/Topic? 0
  • +

Replies To: Javascript (.jsp) : Captcha validation error message

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4353
  • View blog
  • Posts: 12,160
  • Joined: 18-April 07

Re: Javascript (.jsp) : Captcha validation error message

Posted 29 November 2011 - 03:24 PM

I notice that you have a replaceWith call that you are using to replace the element with the id #messageCode2 with a new element that has an ID #messageCode. replaceWith will completely replace that element. Once this line executes the first time, there is no #messageCode2 anymore. It is now #messageCode instead.

My guess is that the second time you run it, your jQuery is looking for #messageCode2 is not going to match any elements because now it sees #messageCode, not #messageCode2.

I hope you get what I am saying. To fix it, the element you replace it with should also have the same id of #messageCode2.

See if that fixes the problem for you. :)

This post has been edited by Martyr2: 29 November 2011 - 03:25 PM

Was This Post Helpful? 1
  • +
  • -

#3 Mohan3088  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 11

Re: Javascript (.jsp) : Captcha validation error message

Posted 29 November 2011 - 07:59 PM

Thank you my brother.. it works.. i missed that.. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1