-1

one input in my form is completed by a variable javascript. I do not understand why my php code does not see this variable? (if I enter the value manually, it will work)

 <?php $kwota2 = $_POST['kwota2']; // undefinded kwota2 ?? ?>

    <form action="post>
    <input id="kwota2" type="text" name="kwota2" disabled>

    <script>
           $("#kwota2").val(localStorage.getItem('sumalist'));
    </script>
<input type="submit" value="Zamawiam">
                    </form>
A. Jo
  • 15
  • 5

2 Answers2

0

Its not working because its marked it as disabled convert it into readonly and try

and add your javascript code in document ready function

Niraj Savaliya
  • 179
  • 1
  • 14
0

This is the first method. You will serialize objects that are disabled with jQuery.

$('form').on('submit', function(e) {
  e.preventDefault();
  
  var data = $('form').serializeArray();
  $(':disabled').each(function(i, item) {
    data.push({
      name: item.name,
      value: $(this).val()
    });
  });
  console.log(data);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="post">
  <input id="kwota2" type="text" name="kwota2" value="example" disabled>
  <input type="submit" value="Zamawiam">
</form>

The second method is to add the readonly property.The only difference between disabled and readonly is readonly serializable.

<form action="post">
  <input id="kwota2" type="text" name="kwota2" value="example" readonly>
  <input type="submit" value="Zamawiam">
</form>

Also : How to make $.serialize() take into account those disabled :input elements?

Özgür Can Karagöz
  • 1,039
  • 1
  • 13
  • 32