Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery get element attribute and insert it to an input text

I need help for this issue. I have a list of file and in each one a checkbox input. So i need to check one of that checkboxes and when click on "Insert" button, get the attribute value and insert it to that text input. I appreciate your help.

here is my html code link:

http://jsfiddle.net/Qd3n5/4/

<div class="download_list">
    <div>
        <p class="name"> <a href="#" title="samle-image.gif" class="File_Name">samle-image.gif</a>

        </p>
    </div>
    <div class="size-text">
        <input type="checkbox" name="delete" value="1" class="toggle">
    </div>
</div>
<div class="download_list">
    <div>
        <p class="name"> <a href="#" title="favicon.ico" class="File_Name">favicon.ico</a>

        </p>
    </div>
    <div class="size-text">
        <input type="checkbox" name="delete" value="1" class="toggle">
    </div>
</div>
<div class="download_list">
    <div>
        <p class="name"> <a href="#" title="freedown.jpg" class="File_Name">freedown.jpg</a>

        </p>
    </div>
    <div class="size-text">
        <input type="checkbox" name="delete" value="1" class="toggle">
    </div>
</div>
<div class="fileupload">
    <button type="button" id="Inser_btn" class="btn btn-primary Inser_btn"> <i class="UpIcon icon-remove"></i>
 <span>Insert</span>

    </button>
</div>
<div class="test">
    <input type="text" name="banners_image_local" value="some-text.png" size="51" maxlength="64">
</div>
like image 764
Martian.titan Avatar asked Mar 28 '26 05:03

Martian.titan


2 Answers

You can try this :

$(function(){
    $('#Inser_btn').click(function(){
        var title='';
        $('input[name="delete"]:checked').each(function(){
            title+=$(this).closest('.size-text').prev().find('a').attr('title');
        });
        $('input[name="banners_image_local"]').val(title);
    });
});

Demo

like image 185
Bhushan Kawadkar Avatar answered Mar 29 '26 20:03

Bhushan Kawadkar


Use this piece of Code

$("#Inser_btn").click(function(){
var val = $(".toggle:checked").parent().siblings().eq(0).find("p a").text();
$(".test input").val(val);

});

JSFIDDLE

like image 22
Sunil Hari Avatar answered Mar 29 '26 21:03

Sunil Hari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!