Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want an alert message to trigger conditionally, i.e if condition is false this alert should trigger.

Dont want any key click etc. event.

What I have tried:

JavaScript
if (state && disc > 100)
			{
				$.createAlert({
					title: 'You have reached the limit or your quota!',
					template: `
					<p> A Message goes here! <p>
					confirmText: 'Accept',
					confirmStyle: 'blue',
					callback: null
				});
				$.showAlert();
				$("#DiscountAmount").val(0);
				return false;
			}


Code from: This website
Posted
Updated 20-Aug-20 2:50am
Comments
Richard MacCutchan 20-Aug-20 7:24am    
What is the problem?
nyt1972 20-Aug-20 7:27am    
Alret not working

1 solution

I am not sure which library you are using to show alert here but quick Google did not give me a result that matched your syntax.

So, suggesting couple of other jQuery based alerts/dialog that can be used. Seems you have condition block in place, all you need is to invoke the alert from there.

Try:
Dialog | jQuery UI[^]
HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog" ).dialog();
  } );
  </script>
</head>
<body>
 
<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
 
 
</body>
</html>

Another option:
jquery-confirm.js | The multipurpose alert & confirm[^]
JavaScript
// Would need javascript file references too

$.alert({
    title: 'Alert!',
    content: 'Simple alert!',
});

There are many, pick a simple one and use it.

BTW, simplest of it is windows.alert: Window alert() Method[^]
 
Share this answer
 
Comments
nyt1972 20-Aug-20 11:09am    
Thanks Sandeep but I wanted a fancy one, and without clicking a button, if I change this textbox value and if the condition is true.
Sandeep Mewara 20-Aug-20 11:12am    
Does not this fall into fancy category? https://craftpip.github.io/jquery-confirm/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900