0

I am new to php and i am facing a problem that when i scan a product from barcode in a field than my form is auto submitted before it fetch the data from database to display in the fields.

Here is a screenshot of form

enter image description here

<form method="post" action="">
  <div class="row" id="itemRows">
    <div class="col-md-2"></div>
    <div class="col-md-6">
      <input type="button" class="btn btn-block btn-primary" style="margin-top: 20px;" id="trainer" onclick="addRow(this.form);" value="Add Row" />
    </div>
    <div class="col-md-2"></div>
    <div class="col-md-2">
      <h3>Grand Total:</h3>
      <input class="form-control" type="text" name="Grand_total" placeholder="" id="Grand_total" readonly />
      <input class="btn btn-primary btn-block" style="margin-top: 10px;" type="submit" name="submit">
    </div>
    <div class="col-md-3">
      <h4>Select Product</h4>
      <input type="text" class="form-control" name="product" id="rowNum0" onchange="total('0');" autofocus />
    </div>
    <div class="col-md-3">
      <h4>Product Name</h4>
      <input class="form-control" type="text" id="p_name" name="" readonly />
    </div>
    <div class="col-md-2">
      <h4>Enter Quantity</h4>
      <input id="qtn0" class="form-control" placeholder="Enter Quantity" type="number" name="add_qty" onchange="total('0');"/>
      <!-- <input type="hidden" id="" value="" > -->
    </div>
    <div class="col-md-2">
      <h4>Price</h4>
      <input class="form-control price" type="text" name="add_price" readonly />
    </div>
    <div class="col-md-2">
      <h4>Total Price</h4>
      <input  class="form-control price t_price0" id="t_price0"  type="text" name="add_total" value="" readonly />
    </div>
 </div>
</form>
htshame
  • 6,599
  • 5
  • 36
  • 56

1 Answers1

0

You have to prevent Enter key on input text. This behaviour is common with forms, when you press enter in textbox it will submit the form.

jigs_
  • 286
  • 5
  • 12
  • I don't press any enter key. It automatically submit the data. Is there a way to Prevent this than provide the solution . Effort is Appreciated – arslan sheikh Apr 19 '19 at 11:03
  • bar code reader does the same thing i think. you can check this answer https://stackoverflow.com/questions/895171/prevent-users-from-submitting-a-form-by-hitting-enter – jigs_ Apr 19 '19 at 11:06