How to assign the value of a javascript variable to a php variable

前端 未结 3 461
广开言路
广开言路 2021-01-26 07:53

I\'ve a form.

相关标签:
3条回答
  • 2021-01-26 08:37

    add two hidden input to your form and use jQuery to change their value

    0 讨论(0)
  • 2021-01-26 08:42

    Try this:

    var pos = $('#name').position();
    $("form").append('<input type="hidden" name="name_position" value="' + pos.left + ',' + pos.top + '" />');
    

    Then read name_position value from the POST data in the server side code.

    0 讨论(0)
  • 2021-01-26 08:48

    The easiest way would be to use a hidden input field and use jQuery to set the value for this input field or these input fields in your case.

    HTML:

    <form action="inc/genxml.php" method="post">
        <input id="nameTxt" name="name" type="text" value="test"/>
        <input id="posLeft" name="posLeft" type="hidden" />
        <input id="posRight" name="posRight" type="hidden" />
        <button id="nameSave" class="left">Save</button>
    </form>
    

    JS:

    $('#nameSave').click(
        function() {
            var pos = $('#name').position();
            $('#posLeft').val(pos.left);
            $('#posRight').val(pos.right);
        }
    );
    
    0 讨论(0)
提交回复
热议问题