topical media & game development

talk show tell print

basic-javascript-12-positioning.htm / htm

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  <html xmlns="">
      <style type="text/css">
          #divBox {
              position: absolute;
              background-color: silver;
              width: 150px;
              height: 150px;
          input {
              width: 100px;
      <script type="text/javascript">
      function moveBox() {
          var divBox = document.getElementById("divBox");
          var inputLeft = document.getElementById("inputLeft");
          var inputTop = document.getElementById("inputTop");
 = parseInt(inputLeft.value) + "px";
 = parseInt(inputTop.value) + "px";
      <div id="divBox">
          <form id="formBoxController" onsubmit="moveBox(); return false;">
              <p>Left: <input type="text" id="inputLeft" /></p>
              <p>Top: <input type="text" id="inputTop" /></p>
              <p><input type="submit" value="Move The Box" /></p>

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.