简体   繁体   中英

2 drop down boxes with 2 submit buttons, which one was clicked?

I have 2 drop down boxes with the same name with 2 submit buttons (for each)

One appears at the top of the page and the other appears at the bottom. Both have the same function ("Cancel" or "Update" records in my grid)

I have this code:

$(div).on('click', '.action-submit', function (e) {
    e.preventDefault();
    var action = $(".action-input");

However when I do a:

if (action.val() == "")

And one of the drop downs aren't selected, it fails the check. Both have to be selected.

How can I determine which drop down box is being worked with? Or am I forced to give them separate names and check for both everytime?

If I understood your question correctly, you should be able to just use e.target .

Sample implementation is as follows: Sample Jsfiddle

JS:

$('div').on('click', function(e) {
    $(e.target).css('background', 'yellow');
});

HTML:

<div>One div</div>
<div>Another div</div>
var action = $(this);

这样,您可以检查单击的内容。

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