Code Snippets

  

JavaScript Source Code


Welcome to Dream.In.Code
Getting Help is Easy!

Join 98,767 Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 1,013 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert

Register to Make This Box Go Away!



Pop-up

a few different ways of pop-ups

Submitted By: pal121
Actions:
Rating:
Views: 11,918

Language: JavaScript

Last Modified: February 11, 2006
Instructions: copy and paste and change text to what you want it too be!

Snippet


  1. <html>
  2. <head>
  3.  
  4. <!-- alert box with line break -->
  5. <script type="text/javascript">
  6. function disp_alert()
  7. {
  8. alert("Hello again! This is how we" + '\n' + "add line breaks to an alert box!")
  9. }
  10. </script>
  11.  
  12. <!-- prompt box -->
  13. <script type="text/javascript">
  14. function disp_prompt()
  15. {
  16. // this is what is in the prompt box
  17. var name=prompt("Please enter your name","")
  18. // no need to edit next line!
  19. if (name!=null && name!="")
  20. {
  21. // this is what is written when ok is pressed
  22. document.write("Hello " + name + "! How are you today?")
  23. }
  24. }
  25. </script>
  26.  
  27. <!-- confirm box -->
  28. <script type="text/javascript">
  29. function disp_confirm()
  30. {
  31. // this is what comes up in the box
  32. var name=confirm("Press a button")
  33. if (name==true)
  34. {
  35. // this is what is written if you press Ok
  36. document.write("You pressed the OK button!")
  37. }
  38. else
  39. {
  40. // this is what is written if you press Cancel
  41. document.write("You pressed the Cancel button!")
  42. }
  43. }
  44. </script>
  45.  
  46. <!-- Alert box -->
  47. <script type="text/javascript">
  48. function click_alert()
  49. {
  50. // change text in brackets to what you want it to be!
  51. alert("This is an alert box")
  52. }
  53. </script>
  54.  
  55. <!-- This is a alert on load of page -->
  56. <script type="text/javascript">
  57. function message()
  58. {
  59. // change text in brackets to what you want it to be!
  60. alert("Pop-up on load!")
  61. }
  62. </script>
  63.  
  64. <body onLoad="message()">
  65.  
  66. <!-- displays alert on click -->
  67. <form>
  68. <!-- change to what you want! -->
  69. <input type="button" onclick="click_alert()"
  70. value="Click Me!">
  71. </form>
  72.  
  73. <br>
  74.  
  75. <!-- displays a option box on click -->
  76. <form>
  77. <!-- change yo what you want! -->
  78. <input type="button" onclick="disp_confirm()"
  79. value="Click Me">
  80. </form>
  81.  
  82. <!-- displays a prompt box -->
  83. <form>
  84. <!-- change to what you want! -->
  85. <input type="button" onclick="disp_prompt()" value="Display a prompt box">
  86. </form>
  87.  
  88. <!-- displays an alert box with a line break -->
  89. <form>
  90. <!-- change to what you want! -->
  91. <input type="button" onclick="alert()" value="Alert with break">
  92. </form>
  93.  
  94. </body>
  95. </html>

Copy & Paste


Comments


HelenChitra 2008-01-04 00:24:48

In line 91, we should call the function disp_alert() onclick. Hence it should be

HelenChitra 2008-01-04 00:43:23

I'm learning JavaScript and this is really helpful. Great.


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->