dvirus
dvirus

Reputation: 211

pass data to lable in same page using jquery

i have this working code with this code i can pass data to div within same page but insted of passing data to div i want to pass this to label or textbox so that i can post it to the server. i am new in ajax,jquery . please suggest me best answer

<script type="text/javascript">

//send clicker data to div
    $(function() {  
        $(".clicker").mouseover(function(){
            var data = $(this).attr('id');
            $.ajax({
                type: "POST",
                data: "db_data=" + data,
                success: function(){
                    //alert(data);
                    $('.responseDiv').text(data);
                }
            });
        });
    });
</script>
<script type="text/javascript">

i think i need to change this line only

$('.responseDiv').text(data);

but dont know how to do that. didnt find any solution on net also

Upvotes: 1

Views: 1212

Answers (3)

Hanky Panky
Hanky Panky

Reputation: 46900

take any name like propertyId

Let's say the text field has id="propertyID"

Use the val() method to assign this new value to your text field.

$('#proertyID').val(data);

Like:

$(function() {  
    $(".clicker").mouseover(function(){
        var data = $(this).attr('id');
        $.ajax({
            type: "POST",
            data: "db_data=" + data,
            success: function(){
                //alert(data);
               // $('.responseDiv').text(data);
               $('#proertyID').val(data);
            }
        });
    });
});

Upvotes: 1

Kamal
Kamal

Reputation: 794

<script type="text/javascript">  //send clicker data to div
$(function() {  
    $(".clicker").mouseover(function(){
        var data = $(this).attr('id');
        $.ajax({
            type: "POST",
            data: "db_data=" + data,
            success: function(data2){
                //alert(data);
                $('.responseDiv').text(data2);
            }
        });
    });
});

success return in data2 and use this..

Upvotes: 0

Praveen D
Praveen D

Reputation: 2377

In the below line change selector .responseDiv with id/name or class of input/label $('.responseDiv').val(data);

Upvotes: 0

Related Questions