how to pick dynamic textbox values created by javascript in php

644

I have inventory sale form where I am selecting items from list, I am getting there values and assigning the same to newly created textbox by clicking on each item using javascript customer requires different items with different quantity's, so i am using javascript for that purpose, when customer click on an item it creates text box which will take number of quantitys to process further, now the issue is how i will pick it up in php file, like before there was two boxes and I know the name of them so I set it asif isset($_POST['txtboxname']) && isset($_POST['anothertxtboxname'])) but now the textbox is been creating dynamically, Items in list are coming from database, how should I handle that?

 <script>

 function createFunc() {

  var getForm = document.getElementById("theForm");  
  var getElem = document.getElementById("selectMultiple");
  var optValue = getElem.options[getElem.selectedIndex].value;
  var optName = getElem.options[getElem.selectedIndex].text;

  var qtyDiv = document.getElementById("quantityDiv");

  var createInput = document.createElement("input");
    createInput.type = "text";
    createInput.name = optValue;

   qtyDiv.appendChild(createInput);

  }

  </script>

  <html>

  <form id="theForm" action="testpht.php" method="POST"  
  enctype="multipart/form-data">


  <select id="selectMultiple" name="select_pro[]"  
  multiple="multiple" onchange="createFunc()" >

  <option>SELECT PRODUCT</option>  

  <?php 

  include 'mysql_connect.php';
  $objDbClass = new DBConfig();
  $conn = $objDbClass->get_db_pdo_func();

  $sql = "SELECT pro_id,pro_name,quantity FROM products ORDER BY pro_name  
  ASC";

  $query = $conn->query($sql);
  $result = $query->fetchAll(PDO::FETCH_ASSOC);
  $arrlength = count($result);

  for ($x = 0; $x < $arrlength; $x++){

  ?>    

  <option value="<?php echo $result[$x]['pro_id']; ?>">
  <?php echo $result[$x]['pro_name']; ?> <?php } ?>

  </option> </select>

  <div id="quantityDiv"></div>

  input value="submit" type="submit" > </form>
  </html>

People are also looking for solutions to the problem: php - Sort array keys by date

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.