Trigger a button click with JavaScript on the Enter key in a text box

In jQuery, the following would work: $(“#id_of_textbox”).keyup(function(event) { if (event.keyCode === 13) { $(“#id_of_button”).click(); } }); $(“#pw”).keyup(function(event) { if (event.keyCode === 13) { $(“#myButton”).click(); } }); $(“#myButton”).click(function() { alert(“Button code executed.”); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> Username:<input id=”username” type=”text”><br> Password:&nbsp;<input id=”pw” type=”password”><br> <button id=”myButton”>Submit</button> Or in plain JavaScript, the following would work: document.getElementById(“id_of_textbox”) .addEventListener(“keyup”, function(event) { event.preventDefault(); … Read more

How to call a PHP function on the click of a button

Yes, you need Ajax here. Please refer to the code below for more details.   Change your markup like this <input type=”submit” class=”button” name=”insert” value=”insert” /> <input type=”submit” class=”button” name=”select” value=”select” />   jQuery: $(document).ready(function(){ $(‘.button’).click(function(){ var clickBtnValue = $(this).val(); var ajaxurl=”ajax.php”, data = {‘action’: clickBtnValue}; $.post(ajaxurl, data, function (response) { // Response div goes … Read more