www.webdeveloper.com
Results 1 to 3 of 3

Thread: Increment 'n' number of individual text boxes??!?

  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Exclamation Increment 'n' number of individual text boxes??!?

    Hi, I have a web-based inventory system that uses a MySQL database. First a user inputs a brand to search for, then he is asked which items (in that brand) he wishes to update. The users is then brought to an update page that should (I NEED HELP!) allow him to increment or decrement the present quantity in inventory. This project utilizes PHP, MySQL, and Javascript. Currently, I can increment or decrement only one item. I need to be able to increment each individual textbox for database updating. How do I do it?


    <html>
    <title>Update Selections</title>
    <body>
    <?php
    include("menu.php");
    include("sqlconnect.php");


    ?>
    <script type="text/javascript">

    function add()
    {
    var TextBoxValue = document.getElementById("value");
    var number = parseInt(TextBoxValue.value, 10);
    TextBoxValue.value = number + 1;
    }

    function subtract()
    {
    var TextBoxValue = document.getElementById("value");
    var number = parseInt(TextBoxValue.value, 10);
    TextBoxValue.value = number - 1;
    if (TextBoxValue.value < 0)
    {
    alert("The present quantity cannot be less than 0!");
    TextBoxValue.value = 0;
    }
    }

    </script>


    <p align="center"><b>Make Updates:</b>
    <br />
    <br />
    The following items were selected for quantity update:
    <br />
    <br />
    <table border="1">
    <tr><th>Item:</th>
    <th>QUANTITY</th>
    <th>ADD/SUBTRACT</th></tr>
    <style>
    textarea {resize: none;}
    </style>
    <?php

    //$row_id = $_POST['itemselect'];
    foreach ($_POST['itemselect'] as $confirm)
    {

    $result = mysql_query("SELECT * FROM inventory WHERE id='$confirm'");
    while ($row = mysql_fetch_array($result))
    {
    echo "<tr><td>" . $row['Item'] . "</td>";
    echo "<td bgcolor='grey'><input type='text' id='value' name='itemupdate[]' disabled='disabled' style='text-align: center' value='" . $row['QuaninInventory'] . "'></td>";
    echo "<td><div align='center'><input type='button' value='+' onclick='add()'><input type='button' value='-' onclick='subtract()'></div></td></tr>";

    }
    }
    echo "</table>";
    ?>
    <br />
    <br />
    <INPUT TYPE="BUTTON" VALUE="<-- Back to Results" ONCLICK="window.location.href='http://localhost/Inventory/quantitybybrandprocess.php'">
    </p>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,675
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function add(obj,ud){
     while (obj.parentNode){
      if (obj.nodeName.toUpperCase()=='TR'){
       obj=obj.getElementsByTagName('INPUT')[0];
       break;
      }
      obj=obj.parentNode;
     }
     if (obj.nodeName.toUpperCase()=='INPUT'){
      obj.value=Math.max(obj.value*1+ud,0);
     }
    }
    
    
    /*]]>*/
    </script></head>
    
    <body>
    <table>
    <tr>
    <td>Tom</td>
    <td bgcolor='grey'><input type='text' id='value' name='itemupdate[]' disabled='disabled' style='text-align: center' value='10'></td>
    <td><div align='center'><input type='button' value='+' onclick='add(this,1)'><input type='button' value='-' onclick='add(this,-1)'></div></td>
    </tr>
    <tr>
    <td>Tom</td>
    <td bgcolor='grey'><input type='text' id='value' name='itemupdate[]' disabled='disabled' style='text-align: center' value='10'></td>
    <td><div align='center'><input type='button' value='+' onclick='add(this,1)'><input type='button' value='-' onclick='add(this,-1)'></div></td>
    </tr>
    </table>
    
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Jun 2012
    Posts
    2

    Thumbs up

    Thank you so much... It works perfectly. Though I don't quite understand how it works

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles