Assign value to input text

Asked

Viewed 320 times

0

I have the code below that is working perfect, IE, whenever I move the images appears to me the left and top scales of the same. However it is appearing with LI and I need it to appear in the VALUE of an INPUT TYPE=TEXT, because I need to send the result to database via PHP and MYSQL.

If friends can help me, I’d be 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>

1 answer

3

Test like this instead of using the function .text() use the .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 changes the li for input with the same id:

<input type="text" id="posX" />
<input type="text" id="posY" />
  • Thanks Mastria, worked well. Thank you so much for the tip.

  • 1

    @Murilocabral if it worked mark as correct the answer so that other people are benefited in future research. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.