javascript - Get textbox input values in JS function on button click -


i'm trying textbox inputs in js function on click of button. reason console.log not show textbox inputs. how accomplish this?

index.php:

  <input placeholder="name" type='text' name='username' id='username'  maxlength="50" />   <input placeholder="password" type='password' name='password' id='password' maxlength="50" />   <button id="testajax" onclick="utilities.loadsavedgames()">load game</button> 

js/utilties.js

var utilities = {     loadsavedgames : function () {      var username = document.getelementbyid('username').value,         password = document.getelementbyid('password').value;     console.log(username + ", " + password); //null, blank 

possibly have elements duplicate ids on same page. try code in browser console: $('[id=username]').length , $('[id=password]').length. if count > 1, have multiple elements same id.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -