-2

I can not pass the id of my buttons in ajax, it appears MY_id undefined as output from console.log can someone help me ?

my problem is when I choose my imagebutton and then I click on my send button. the value of the id of the imagebutton is not captured, how do I solve it?

<html>
    <input type="image" id="name-1" src="img.png"  onclick="reply_click(this.id)" class="btTxt submit "  width="100" height="130" /> 
    <input type="image" id="name-2" src="img.png" onclick="reply_click(this.id)" class="btTxt submit"  width="100" height="130" /> 
    <input type="image" id="name-3" src="img.png" onclick="reply_click(this.id)" class="btTxt submit" width="100" height="130" /> 
    <input type="image" id="name-N" src="img.png" onclick="reply_click(this.id)" class="btTxt submit" width="100" height="130" /> 
    <button type="MYbutton" id="openButton" class="btn btn-primary">MYtext</button>
        <script>
            function reply_click(clicked_id ){
                $(function() {
                    $('#openButton').on('click', function() {
                          var x = document.getElementById(clicked_id).innerHTML;
                        $.get('MYURL.com',function(data){
                            console.log('MY_id'+ x);
                        });
                    });
                });
            }
        </script>
    </html>
Community
  • 1
  • 1
the flash two
  • 47
  • 1
  • 12

1 Answers1

0

This code solved my problem.

      <script>
            function reply_click(clicked_id){
                $(function() {
                    $('#openButton').on('click', function() {
                        $.get('MY_URL',function(data){
                            console.log('MY_id:  '+ clicked_id);
                        });
                    });
                });
            }
</script>
the flash two
  • 47
  • 1
  • 12