www.webdeveloper.com
Results 1 to 6 of 6

Thread: problem in getting data using document.getElementById

  1. #1
    Join Date
    Oct 2011
    Posts
    350

    problem in getting data using document.getElementById

    Hi...

    I got an error: Object Required when I use this code:

    Code:
        var SubQty = document.getElementById("SubQty").value;
    
    <input class='txt' type='text' name='SubQty[]' id='$joinId' size='12' style= 'border:none;' value=''/>
    How can I get the value?

    Thank you

  2. #2
    Join Date
    Mar 2009
    Posts
    512
    In your listed code the id is '$joinId' not 'subQty'. Try that instead.

  3. #3
    Join Date
    Oct 2011
    Posts
    350
    here is my whole code:

    Code:
    <?php                                                                          
       error_reporting(0);
       date_default_timezone_set("Asia/Singapore"); //set the time zone  
    $con = mysql_connect('localhost', 'root','');
    
    if (!$con) {
        echo 'failed';
        die();
    }
    
    mysql_select_db("mes", $con);
    
    ?>
    <html>
    <title>Stock Requisition</title>
    <head>
    <link rel="stylesheet" type="text/css" href="kanban.css">
    
    
    
    <script type="text/javascript">
    function save_sr(){
    
        var SubQty = document.getElementsById("joinId").value;
        
    
    }
    
    
    </script>
    
    <script type="text/javascript">
    
    function test_(cmpd) {
        var len_ = (document.frmMain.elements.length) - 1;
      
         for (i=0; i <= len_; i++ ) {
    
           var strPos_ = document.frmMain.elements[i].id.indexOf(cmpd)
    
                  if (strPos_ != -1) {
                  var strPos = document.frmMain.elements[i].id.indexOf("_");
                  
    var strId = document.frmMain.elements[i].id.slice(strPos + 1) + "_" + document.frmMain.elements[i].id.slice(0,strPos)               
       document.frmMain.elements[i].value = Math.round((document.getElementById(strId).value * document.getElementById('DemandedQty').value) * 100 ) / 100;  
         } 
        }  
    }
    </script>
    
    </head>
    <body>
    <form name="frmMain"  method="post">
    
    
       <div>
    <table>
    <thead>
    <th>Items</th>
    <th>Sub Items</th>
    <th>Item Code</th>
    <th>Demanded Qty</th>
    <th>UoM</th>
    <th>Class</th>
    <th>Description</th>
    <th>BIN Location</th>
    </thead>
    <?php
    
    $DemandedQty = $_POST['DemandedQty'];
    
    $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
    $res_bom = mysql_query($sql, $con);
    while($row = mysql_fetch_assoc($res_bom)){
        
        $Items = $row['Items'];
        $Items_ = substr($Items, 12, 3);
        
    echo "<tr>
            <td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$Items_' name='Items_[]' id='Items_' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
            <td style='border:none;'>&nbsp;</td>
            <td style='border:none;'>&nbsp;</td> 
            <td style='border: none;'><center><input type='text' style='text-align: right;' name='DemandedQty[]' id='DemandedQty' size='12' onkeyup='test_(\"$Items_\")'></center></td>     
            </tr>"; 
                 
    $sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items"or die(mysql_error());
    
    $res_sub = mysql_query($sql, $con);  
     $counter = 0;
     while($row_sub = mysql_fetch_assoc($res_sub)){
         $joinId = $counter . "_" .  $Items_;      
         $Items = $row_sub['Items'];
         $Items1 = substr($Items, 12, 3);
         $SubItems = $row_sub['SubItems'];
         $ItemCode = $row_sub['ItemCode'];
         $UoM = $row_sub['UoM'];
         $Class = $row_sub['Class'];
         $Description = $row_sub['Description'];
         $BINLocation = $row_sub['BINLocation'];
         $Quantity = $row_sub['Quantity']; 
         $joinId2 =  $Items_ . "_" . $counter;
    
        echo "<tr>
            <td style='border: none;'>&nbsp;<input type='hidden' value='$Items1'  name='Items1[]' id='Items1'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='SubItems[]' id='SubItems' value='$SubItems'  readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='ItemCode[]' id='ItemCode' value='$ItemCode'  readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
            <td><input class='txt' type='text' name='SubQty[]' id='$joinId' size='12' style= 'border:none;'/><input type='hidden' id='$joinId2' value='$Quantity' /></td>
            <td style='border: none;' size='3'>&nbsp;<input type='text' name='UoM[]' id='UoM' value='$UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Class[]' value='$Class' name='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='Description[]' value='$Description' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size= '30'></td>
            <td style='border: none;'>&nbsp;<input type='text' name='BINLocation[]' value='$BINLocation' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>     
            </tr>";    
     $counter  = $counter  + 1;
    }
    } 
                     
    ?>
    </table>
    </div>
    
    
    <div id="save_btn">
    <input type="button" name="button" value="save" onClick="save_sr()" style="width: 5em;">
    
    
    </div>
    </form>
    </body>
    </html>
    Thank you

  4. #4
    Join Date
    Oct 2011
    Posts
    350
    Quote Originally Posted by Tcobb View Post
    In your listed code the id is '$joinId' not 'subQty'. Try that instead.
    What should I try?

    Thank you

  5. #5
    Join Date
    Jan 2011
    Posts
    123
    He said that the "id" of your input element is "$joinId" not "subQty", instead you are feeding the your getElementById method with its "name" property when trying to store a reference to it!
    -My question is: why would you do that?!

  6. #6
    Join Date
    Oct 2011
    Posts
    350
    I resolved it using this code:
    Code:
    var SubQty_ = document.getElementsByTagName('input');    var SubQty = SubQty_[9].getAttribute("value");
    Last edited by newphpcoder; 05-03-2012 at 05:01 AM.

Thread Information

Users Browsing this Thread

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

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