Q:

JQuery hidden field value null when form is serialized and posted

I have the following html script:
<form id="myForm">
...
<input hidden name="myInput" id="myInput">
...
</form>

And somewhere I set a value for the hidden input:
$('#myInput').val('a value here');

then, I serialize the form and post it in an url:
$.post("my_url_here", $("#myForm").serialize())

Where I handle this post, I try to access my hidden input value with:
$_POST['myInput']

but it shows null (empty actually), when I expect it to have the value that I set before. If I explicitly set the value like this:
<input hidden name="myInput" id="myInput" value="explicit_value">

it works fine. Any idea what's going on?
UPDATE (the whole code, the order is the same as in my real code):
<script>

    jQuery( document ).ready(function( $ ) {
           eventHandler(){
             ...
             $('#myInput').val('a value here');
             myPostFunction();
          }
    });

</script>
<form id="myForm">
    ...
    <input hidden name="myInput" id="myInput">
    ...
</form>
<script>

    jQuery( document ).ready(function( $ ) {
           window.myPostFunction= function () {
             alert($("#myForm").serialize());//It shows myField=&otherField=value
             alert($("#myInput").val());// This shows the correct value.
             $.post("my_url_here", $("#myForm").serialize());
          }
    });

</script>

A:

OK, thank you all for your help but finally I found the solution. It was the name of the field that wasn't OK. I just changed the name of the field and it is fine now. It should have been a conflict with the name but I did't realize it since the script executed fine. After trying all, I thought to change the name... Again, thank you all!

