0

I am trying to achieve similar action like confirm/prompt does in javascript.

A user clicks a link to appear a pop-up with username and password input field. The user will input his details and goes forward if the user is valid.

I have a page with many buttons with different actions(achieve via AJAX). All of these button needs to check username and password validation before it could go forward. Hence, I want to use if condition for "validuser" function which will prompt user to key in username and password and later return true or false to execute respective action of the button.

I hope it is possible to do so.

<div class="popup">
 <input type="text" name="username"/>
 <input type="text" name="password"/>

 <p class="cancel">Cancel<p>
 <p class="OK">OK<p>
</div>


function validuser(){

  $(".popup").show();

  //if clicked Cancel then RETURN FALSE

  //if clicked OK then run ajax => RETURN TRUE OR FLASE

}

$('.btn').click(function(){

//check if the user is valid
if(validuser()){
      //do something
   }
});`
  • This is entirely possible. Where does your code gives errors? We can help with debugging your code, but won't write your code for you. – Shilly Nov 19 '15 at 15:07
  • If left unedited, I am unsure whether to flag this question as either too broad or why isn't this code working... either ways please give us more details, the implementation is everything in terms of how your question should be addressed – AGE Nov 19 '15 at 15:11
  • As you're basically asking how to return the result of an async callback, I'm closing this as a duplicate of the other more general answer. Let me know if you update the question to be about a different related issue within this scope, and I'll reopen. – zzzzBov Nov 19 '15 at 15:21
  • I have now updated the question. I hope that makes sense. – user1568402 Nov 19 '15 at 15:41
  • @user1568402, It's easy to see what you're trying to do, but the question is far too broad and you haven't actually shown any code that you've attempted to solve your own problem, nor have you asked about a specific issue you're having trouble with. – zzzzBov Nov 19 '15 at 16:31

0 Answers0