Jump to content

[SOLVED] Add +1 to numeric field?


Jason28

Recommended Posts

Hello, can anyone provide me with a working code that allows me to click a button to add +1 to the current field?  So if a field has the number 12, I can click on a button to make it 13.  Thanks!

 

<html>
<head>
   <title>Increment by 1</title>
   <script type="text/javascript">
   window.onload = function()
   {
      var myButton = document.getElementById("myButton");
      var myInput = document.getElementById("myInput");

      myButton.onclick = function()
      {
         myInput.value = parseInt(myInput.value) + 1;
      }
   }
   </script>
</head>

<body>

Add 1 to: <input id="myInput" name ="myInput" type="text"><br />
<button id="myButton" value="Add 1!">

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.