1.11M Members

how to detect who clicked?

 
0
 

Hello

I have a code and on page load it gets clicked, I see by alert for example. The problem is it send not needed ajax request. Its hard to find origin clicker by hand. Is there a way programically detetc who clicked the class?

//Delete all event from betting slip
    $('.clear_all_slip').click(function() {

        alert('who click?');

        clear_choose_bet();

        $.getJSON(base_url_lang + "ajax/clear_slip/", function(data){

            if (data.length == 0) {
                $('#current_slip').html('');
                $('#express_slip').html('');
                $('#system_slip').html('');

                count_express_total_odd();

                $('#to_win_ordinary').text('0');
                $('#to_win_express').text('0');
                $('#to_win_system').text('0');
                $('#total_odd').text('0');
                $('#system_stake_total').text(0);
                $('#stake_per_bet').attr('value', '');
                $('#stake_express').attr('value', '');

            }
        });
    }); 
 
0
 

Look for click() anywhere in your code.

 
0
 

Use "this"

this - refers to the element who clicked it
or you may use the event obj.

e.g. (this)

console.log('element who clicked', this);

e.g. (event)

$('.clear_all_slip').click(function(event) {
  console.log('target', event.target);
});
 
0
 

thanks, I will try with this and even.target.

Look for click() anywhere in your code.
I did, but it took much more time, because even when seach function found it, I did not notice right away - it was hidden between search results :)

 
0
 

I tested, but there is a problem. I see the element WHICH was clicked, but not WHO clicked. I mean when not human clicks. I am having another problem - using barcode scanner - it clicks for some reason the link, and I don't get from where it clicks.
Like in PHP there is function stack or somethign like that.

 
0
 

There is a return as one of the characters, so it will click the default submit button (at least that's my guess). Had something similar happen before with a mag reader.

 
2
 

As far as I know, barcode scanner work as a keyboard. So it may be sending an Enter key that click the default submit button, as said by stbuchok.

I'd suggest you to remove any <button type="submit" /> and <button /> and try it again.
Ps.: Buttons without types are treated as submit type too.

 
0
 

yeah, I find out that it sends #13 key, and made a workaroud - when script detects it, I do apropriate actions. But still for me does not make sence why the link is clicked. I mean enter key with keyboard does not click the link. And when I detected that 13 key and made it not react, the problem gone. Just would be interesting to know why it could happen. For better understanding I show the workaroudn code part:

else {  //focus on nothing - try to read/scan barcode

            if (e.which >= 48 && e.which <= 57) {    //if number

                current_barcode += String(e.which-48);

                if (current_barcode.length == 10) {

                    //there is hidden barcode input for all shop pages, so this is submited
                    $('input[name=barcode]').val(current_barcode);

                    if (current_method != 'main') {
                        $('#hidden_check_barcode [name=check_submit]').click(); // the page here is redirected
                    }
                    else {
                        open_page('payout');

                        // scanned_barcode - from redirection
                        // current_barcode - in this file variable
                        if (scanned_barcode.length != 10 && current_barcode.length != 10) {
                            reset_payout_page('reset_fields');  // for barcode scan its bad to reset
                        }
                        else {
                            // barcode posted from other page - so check it
                            check_ticket();
                            scanned_barcode = ''; // reset so next time when opening page barcode would not be filled in and checked
                        }

                    }
                }

            } else {

                if (current_barcode.length == 10 && e.which == 13) {
                    // otherwise it catches #13 key (last barcode char probably)
                    // which is not needed and cause problems - for unknown reason link of the game gets clicked
                    e.preventDefault();
                }

                //if something else pressed, reset
                current_barcode = '';

            }

        }
 
0
 

It's an <a> or an <button>?

 
0
 

It's an <a> or an <button>?

link which should not be clicked on snanning is <a>, or I did not understand the question

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article