I have been trying to resolve this problem, I am using some node module which I'd need at client side and hence, I am using browserify to generate a build.js file. When I am using this file, I am getting:
Uncaught TypeError: Cannot read property 'value' of null for values
and
Uncaught ReferenceError: [function_name] is not defined for functions on button click events..
When I tried moving the events from inline "onclick" to someButton.addEventListener('click', function(e)) then nothing happens, not even an alert works.
Its similar to the problem described in this question: Using browserify, Uncaught ReferenceError: function is not defined, but the solution didn't help.
Here is my javascript file which i am using to create a build using browserify (outBrowserify.js):
var serverName = "http://127.0.0.1:9000";
var socket = io.connect(serverName);
console.log('CLient connecting to server: ' + serverName);
socket.on('ConnectionConfirmation', function(data){
console.log('Message from server: ' + data.text);
});
var Firebase = require('firebase');
var btnLogin = document.getElementById('btn_validateLogin');
if(btnLogin)
{
btnLogin.addEventListener('click', function(e){ //nothing happens..
alert('function added..');
});
}
var username = document.getElementById('ipt_username');
console.log('username : ' + username.value); //gives an error
function ValidateLoginCredentials()
{
var username = document.getElementById('ipt_username');
var passwd = document.getElementById('ipt_password');
console.log(username.value);
console.log(passwd.value);
ClientID = username.value;
socket.emit('ValidateLogin', {username: username.value, password: passwd.value});
}
and the HTML is:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/javascripts/outBrowserify.js"></script>
</head>
<body>
<div id="login">
<table>
<tr>
<td>
<label>Username :</label>
</td>
<td>
<input id="ipt_username" type="text" name="username">
</td>
</tr>
<tr>
<td>
<label>Password :</label>
</td>
<td>
<input id="ipt_password" type="password" name="password">
</td>
</tr>
<tr>
<td colspan="2">
<input id="btn_validateLogin" type="button" value="Validate Login" onclick="ValidateLoginCredentials()">
</td>
</tr>
</table>
</div>
</body>
</html>
The html is converted from index.jade in my application as I am using node.js with express. Also, when I run the script directly, it works except the modules which are unavailable to browser.