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
}
});`