Jump to content

Multiple Alert Boxes?


darrell

Recommended Posts

Make alert boxes on the basis of your conditions. You have to just use javascript alert() function. As i did in below code, it will alert three times. <!DOCTYPE html><html><head><script>function myFunction(){alert("I am an alert box1!");alert("I am an alert box2!");alert("I am an alert box3!");}</script></head><body><input type="button" onclick="myFunction()" value="Show alert box" /></body></html>

Link to comment
Share on other sites

I meant to say how would I make multiple buttons, that each have their own alert.What you've given is one button that shows multiple alerts. Sorry I didn't explain better. I've been experimenting, and found a method that works when I test it, but I'm not sureit is the proper way to code it. <script type="text/javascript">function disp_alert(){alert("Message");}</script><input type="button" onclick="disp_alert()" value="Message" /> <script type="text/javascript">function disp_alert2(){alert("Message 2");}</script><input type="button" onclick="disp_alert2()" value="Message 2" />

Link to comment
Share on other sites

There's no need for an intermediate function, just pass a string to the alert() right where it's being called.

<input type="button" onclick="alert('Something')" value="Message" /><input type="button" onclick="alert('Something else')" value="Message 2" />

  • Like 1
Link to comment
Share on other sites

You shouldn't need to have + '\n' +, you can add the \n right into the string.

alert("Line 1.\nLine 2.");

The only reason you need single-quotes instead of double-quotes is because double-quotes are being used as delimiters for the attribute's value.Hopefully the code parser will color the following codes right so you can get an idea:

var str1 = "Quotation marks "inside" quotation marks";var str2 = 'Double-quotes "inside" single-quotes';var str3 = "Single-quotes 'inside' double-quotes";var str4 = "Double-quotes \"escaped\" inside double-quotes";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...