简体   繁体   中英

Update Form Hidden Field Value wit button ID?

I have a bunch of popover buttons that will open the same form. Now I need the button id value as hidden field inside the form.

html buttons:

<a type="button" class="pop" data-toggle="popover" id="1">Button 1</a>
<a type="button" class="pop" data-toggle="popover" id="2">Button 2</a>
<a type="button" class="pop" data-toggle="popover" id="3">Button 3</a>
...

popover form:

<div id="popover-content" class="hide">
<form>
<input name="name" type="hidden" value="ButtonIDvalue">
...

popover js:

$('.pop').popover({ 
        html : true,
        content: function() {
            return $("#popover-content").html();
        }
    });

You can access the element that triggered the popover as this within the function bound to content . So you could update your code to be:

$('.pop').popover({ 
        html : true,
        content: function() {
            $('#hidden-input').val(this.id);
            return $("#popover-content").html();
        }
    });

Of course using whatever the correct selector is for your hidden input field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM