Assign value to the input text

0

I have the code below that is working perfectly, that is, whenever I move the images I have the left and top scales of the same ones. But this is appearing with LI and I need it to appear in the VALUE of an INPUT TYPE = TEXT, as I need to send the result to the database via PHP and MYSQL.

If friends can help me, I'll be very grateful.

Hugs to all.

jQuery

$('#img').draggable({
    drag: function () {
        var offset = $(this).offset();
        var xPos = offset.left;
        var yPos = offset.top;
        $('#posX').text('Hori: ' + xPos);
        $('#posY').text('Vert: ' + yPos);
    }
});

});

HTML

    <li id="posX">Hori: 0</li>
    <li id="posY">Vert: 0</li>
    
asked by anonymous 13.04.2015 / 15:50

1 answer

3

So, instead of using the .text() function, use .val() :

$('#img').draggable({
    drag: function () {
        var offset = $(this).offset();
        var xPos = offset.left;
        var yPos = offset.top;

        $('#posX').val('Hori: ' + xPos);
        $('#posY').val('Vert: ' + yPos);
    }
});

HTML change the li to input with the same id:

<input type="text" id="posX" />
<input type="text" id="posY" />
    
13.04.2015 / 17:44