0

I'm implementing the Mailgun jQuery email validator. I'm trying to get the submit button on my form to change it's input upon a successful verification. Right now, when I put this replaceWidth code in the validation_error function, nothing happens, even on an error message. However, when I put it in the validation_success function, it triggers with either an error or success. Is there a reason it would work in one function and not the other?

function validation_success(data) {
    $('#status').html(get_suggestion_str(data['is_valid'], data['did_you_mean']));
    $('.signupbtn_new').replaceWith('<input type="submit" name="submit" class="signupbtn_new" value="Signup For Free!" id="email_submit">');
  }




  // if email is invalid
  function validation_error(error_message) {
    $('#status').html(error_message);   


  }             
programmingnewb
  • 129
  • 2
  • 9
  • 1
    And why would you replace the entire input with a new one that is exactly the same ? – adeneo May 06 '14 at 17:52
  • I'm changing the type from button to submit so that the user can't submit unless the email is valid. – programmingnewb May 06 '14 at 17:53
  • Then change the type -> `$('.signupbtn_new').prop('type', 'submit')` – adeneo May 06 '14 at 17:53
  • 1
    Or just disable the input ? – adeneo May 06 '14 at 17:54
  • http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – adeneo May 06 '14 at 17:54
  • Thanks Adeneo, that's a cleaner way to accomplish it. However, it's still not firing when the validation_error function fires. And it always fires if I put it in validation_success. According to the mailgun validator doc https://github.com/mailgun/validator-demo/ the validation_success should only fire if the email is valid. – programmingnewb May 06 '14 at 17:59
  • I know nothing about that plugin, but you could try placing logs in each function and see when they fire, and if there is an issue with the functions firing at the wrong times, you could ask a question specifically about that plugin, that way someone that knows the plugin will most likely answer. – adeneo May 06 '14 at 18:02
  • Hey Adeneo, really appreciate the help. I've used your suggestion to clean up the input type change. I figured out the issue. I misunderstood the validation_success function before. Turns out that comes back as success as long as the service is reached and something is returned. The actual check for email being valid or not is in a different conditional further down in the code. Got it working now. I'm going to package a little app together so that anyone in the future can have an easy time hooking the validator into their own forms. Thanks again. – programmingnewb May 06 '14 at 18:11

0 Answers0