Javascript - Inject HTML into popup window


SUBMITTED BY: Guest

DATE: Oct. 24, 2013, 7:46 p.m.

FORMAT: JavaScript

SIZE: 3.4 kB

HITS: 1171

  1. <html>
  2. <head>
  3. <title>Don's Digital Photo Development</title>
  4. <script type="text/javascript">
  5. var todayDate = new Date();
  6. function loadDate() {
  7. todayDate = new Date();
  8. var month = todayDate.getMonth() + 1;
  9. var day = todayDate.getDate();
  10. var year = todayDate.getFullYear();
  11. currentDate = month + "/" + day + "/" + year;
  12. document.getElementById("date").value = currentDate;
  13. }
  14. function orderReady(days) {
  15. var pickupDate = (todayDate.getMonth() + 1) + '/' +
  16. (todayDate.getDate() + Number(days)) + '/' +
  17. (todayDate.getFullYear());
  18. document.getElementById('pickup').value = pickupDate;
  19. }
  20. function Open_win() {
  21. var name = document.getElementsByName('firstName')[0].value + ' ' +
  22. document.getElementsByName('lastName')[0].value;
  23. var phone = document.getElementsByName('phone')[0].value;
  24. var radio = document.getElementsByName('itemType');
  25. var order = '';
  26. for (i = 0; i < radio.length; i++) {
  27. if (radio[i].checked)
  28. order = radio[i].title;
  29. }
  30. var date = document.getElementById('date').value;
  31. var pickup = document.getElementById('pickup').value;
  32. var popup = window.open("",
  33. "_blank",
  34. "width=400, height=300, menubar=yes, toolbar=yes");
  35. popup.document.writeln("<html><head><title>Order Receipt</title></head>" +
  36. "<body>" +
  37. "<h1>Order Receipt</h1>" +
  38. "<b>Name:</b>" + name + "<br />" +
  39. "<b>Telephone:</b>" + phone +
  40. "<p><b>Order:</b>" + order + "<br />" +
  41. "<b>Order Date :</b>" + date + "<br />" +
  42. "<b>Pickup Date:</b>" + pickup +
  43. "</body></html>");
  44. popup.document.close();
  45. }
  46. </script>
  47. </head>
  48. <body onload="loadDate();">
  49. <form>
  50. <h1>Don's Digital Photo Development</h1>
  51. <p>
  52. First Name: <br /><input type="text" name="firstName" size="50" value="" /><br />
  53. Last Name: <br /><input type="text" name="lastName" size="50" value="" /><br />
  54. Telephone: <br /><input type="text" name="phone" size="50" value="" />
  55. </p>
  56. <p>
  57. Items
  58. <input type="radio" name="itemType" value="1" title="5 x 7 Prints"
  59. onclick="orderReady(this.value)"/>5 x 7 Prints(1 day)
  60. <input type="radio" name="itemType" value="1" title="Poster"
  61. onclick="orderReady(this.value)"/>Poster (1 day)
  62. <input type="radio" name="itemType" value="2" title="Coffee Mug"
  63. onclick="orderReady(this.value)"/>Coffee Mug (2 Days)
  64. <input type="radio" name="itemType" value="3" title="T-shirt"
  65. onclick="orderReady(this.value)"/>T-shirt (3 days)
  66. </p>
  67. <p>
  68. Today's Date: <input type="text" id="date" name="orderdate" size="50"/><br />
  69. Pick-up Date: <input type="text" id="pickup" name="pickupdate" size="50"/>
  70. </p>
  71. <input type="submit" value="Place Order" onclick="Open_win()"/>
  72. </form>
  73. </body>
  74. </html>

comments powered by Disqus