darrell Posted September 17, 2012 Share Posted September 17, 2012 I've followed this tutorial: http://www.w3schools.com/js/js_popup.asp How would I go about creating more than one alert box per webpage? Link to comment Share on other sites More sharing options...
rahultailwal Posted September 17, 2012 Share Posted September 17, 2012 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 More sharing options...
darrell Posted September 18, 2012 Author Share Posted September 18, 2012 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 More sharing options...
Ingolme Posted September 18, 2012 Share Posted September 18, 2012 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" /> 1 Link to comment Share on other sites More sharing options...
darrell Posted September 18, 2012 Author Share Posted September 18, 2012 That's great! On a side note I had to change my line breaks from " + '\n' + " to ' + '\n' + ' (quotes to single quotes) Why is that? Link to comment Share on other sites More sharing options...
Ingolme Posted September 18, 2012 Share Posted September 18, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now