Advertisement
matthewpoer

javascript.dhtml.testing.xhtml

Aug 25th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.19 KB | None | 0 0
  1. <!-- I went looking through the HDD of my old Thinkpad 600 and found
  2. some documents and scripts that I wrote when I was learning JavaScript,
  3. circa 2007. I figured I'd keep them around because they're neat :) -->
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  7. <head>
  8. <meta name="author" content="Matthew K Poer" />
  9.  
  10. <style type="text/css">
  11. #image, #right, #left {
  12. border:1px solid black;
  13. }
  14. #swap{border:3px dotted black;padding:10px;position:absolute;bottom:100px;right:150px;left:150px;background-color:purple;height:40px;}
  15. #right{position:absolute;right:50px;padding:2px;width:100px;height:30px;background-color:pink;}
  16. #left{position:absolute;left:50px;padding:2px;width:100px;height:30px;background-color:lightblue;}
  17. #inputform{position:absolute;top:10px;left:10px;}
  18. #form{}
  19. #textform{border:1px solid black;padding:1px;}
  20. #write{position:absolute;bottom:200px;left:300px;right:300px;height:100px;border:1px solid black;}
  21. </style>
  22. <script type="text/javascript">
  23. function showposition(id){
  24.   var posy = document.getElementById(id).style.top;
  25.   var posx = document.getElementById(id).style.left;
  26.   posy = posy.slice(0, -2);
  27.   posx = posx.slice(0, -2);
  28.   alert("This element, who's id is '"+id+"' is positioned at "+posx+" by "+posy);
  29. }
  30. function toggle(id){
  31.  if (id == "right"){
  32.   document.getElementById('right').style.display = "none";
  33.   document.getElementById('left').style.display = "block";
  34.  }
  35.  else if (id == "left"){
  36.   document.getElementById('right').style.display = "block";
  37.   document.getElementById('left').style.display = "none";
  38.  }
  39.  else {
  40.   alert("omg! wtf?")
  41.  }
  42. }
  43. </script>
  44. <script type="text/javascript">
  45. // WriteFromTextField.js
  46. //
  47. // HTML of field should include these attributes:
  48. // <input type='text' onkeyup='WriteFromTextField(this.id);' id='Identifier' />
  49. //
  50. // The element created by this script is <div> with the id 'write'
  51. // So create your CSS accordingly
  52. //
  53. // I learned this from the JavaScript & DHTML Cookbook by Danny Goodman
  54. // Lessons 14.9, 14.10, and 14.14
  55. //
  56. // Let's begin...
  57.  
  58. function WriteFromTextField(id) {
  59. var element = document.getElementById('write');
  60.  var text = document.getElementById(id).value;
  61.  var text = document.createTextNode(text);
  62.  if (element){
  63.   element.replaceChild(text, element.firstChild);
  64.  } else {
  65.   var element = document.createElement('div');
  66.   element.id = 'write';
  67.   element.appendChild(text);
  68.   document.body.appendChild(element);
  69.  }
  70. }
  71. </script>
  72. <title>Javascript and DHTML Testing</title>
  73. </head>
  74.  
  75. <body>
  76. <img src="../media/images/tux2-small.png" alt="Tux" id="image" style="position:absolute;top:150px;left:150px;" onclick="showposition(this.id);"/>
  77. <div id="swap">
  78.  <div id="right" onmouseover="toggle(this.id)" style="display:none;">Mouse Me</div>
  79.  <div id="left" onclick="toggle(this.id)" style="display:block;">Click Me</div>
  80. </div>
  81. <div id="inputform">
  82.  <form id="form">
  83.   <input type="text" id="textform" value="This Text Goes Away" onclick="this.value=''" onkeyup="WriteFromTextField(this.id);" />
  84.  </form>
  85. </div>
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement