Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use .keypress() in jquery?
    primarykey
    data
    text
    <p>I am trying to use .keypress() because I need for the users to be able to hit enter and the button to be clicked on my modal (this button closes the modal). When I code:</p> <pre><code>$(document).keypress(function () { console.log('keypress'); }); </code></pre> <p>it works but I obviously can't have it on the document or else or hitting enter would close my modal at any time. So I tried this (bc this had the id of my modal):</p> <pre><code>$('#confirmModal').keypress(function () { console.log('keypress'); }); </code></pre> <p>But it does not work. So I thought well maybe its because the modal does not exist yet on the page until the user clicks cancel so I tried:</p> <pre><code>$('#AddLeadGeneral').on('keypress', '#confirmModal', function () { console.log('.on keypress'); }); </code></pre> <p>But this does not work. Interestingly, enough if I replace 'keypress' with 'click' in my .on() function it works. I think I just do not know enough about keypress to work with it properly. Basically, for my modal when one hits enter the default button should be 'No' so that should close the modal as if they clicked it. Does anyone know how to make this work?</p> <p>Steps: Click cancel at the bottom of the page, then hit enter or click No in the modal and you will see the difference in affects.</p> <p><a href="https://scrmqa.autobase.net/Opportunity/General?leadType=FloorUp&amp;searchType=CustomerSearch&amp;firstName=&amp;lastName=x&amp;phone=&amp;address=&amp;postalCode=&amp;emailAddress=&amp;" rel="nofollow">https://scrmqa.autobase.net/Opportunity/General?leadType=FloorUp&amp;searchType=CustomerSearch&amp;firstName=&amp;lastName=x&amp;phone=&amp;address=&amp;postalCode=&amp;emailAddress=&amp;</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload