Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

Automatic keypress on page load

$
0
0

I have an input area where a value has been preset. I would like to make it so that on page-load the "enter" button is pressed on the keyboard to submit the value.

Here is the code:

$('#login-input').keypress(function(e) {
      if (e.which === 13 && $(this).val() != '') {
        player_name = $(this).val();
        logged = 1;
      }
<div id="console_content"><label>Username:</label><input maxlength="10" class="textarea" id="login-input" autocomplete="off" value="Anonymous" type="text"></div>

A solution where I would not need to press enter and the value is submitted is also welcome!


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>