0
I’m having a problem assigning a role to a input
I have 2 HTML templates in Java
var forgotPassword = ' <form action="#">'+
'<fieldset>'+
'<legend class="title"><span class="lang" key = "SendmePassword">Send me password</span></legend>'+
'<div class="input_block">'+
'<div class="input_wrap">'+
'<input type="text" id="sing_email" class="input" placeholder="Email">'+
'<label for="sing_email" class="label_mail"></label>'+
'</div>'+
'<p>Enter a valid e-mail, the password will be sent to you </p>'+
'</div>'+
'<input type="submit" value="Sing IN" class="btn btn_red" id="backtoSingIN">'+
'<input type="submit" value="Send" class="btnSend btn_red" id="send">'+
'</fieldset>'+
'</form>';
//======================
var singIN = '<form action="#">'+
'<fieldset>'+
'<legend class="title"><span class="lang" key = "LogIn">SING IN</span></legend>'+
'<div class="input_block">'+
'<div class="input_wrap">'+
'<input type="text" id="mail" class="input" placeholder="Email">'+
'<label for="mail" class="label_mail"></label>'+
'</div>'+
'<div class="input_wrap">'+
'<input type="text" id="pass" class="input" placeholder="Password">'+
'<label for="pass" class="label_pass"></label>'+
'</div>'+
'</div>'+
'<a href="#" class="forgotPass" id="forgot"><span class="lang" key ="ForgotPassword">Forgot password</span>?</a>'+
'<input type="submit" value="Sing IN" class="btn btn_red">'+
'</fieldset>'+
'</form>';
//================================================================================================================================================
function loadSingIN(){
return singIN;
}
function loadForgotPassword(){
return forgotPassword;
}
I can use both models that way
//LOAD FORGOT PASSWORD
document.getElementById("forgot").addEventListener('click', function(){
console.log("fui clicado");
document.getElementById("root").innerHTML = loadForgotPassword();
});
document.getElementById("send").addEventListener('click', function(){
console.log("fui clicado");
document.getElementById("root").innerHTML = loadSingIN();
});
but when I try to assign a click function to my input with id "send"
it returns me an error on the console
Error:Uncaught Typeerror: Cannot read Property 'addeventlistener' of null
I tried using $(ducument). ready but I couldn’t solve it, someone could help me ?
This error is displayed as there is no input with id "send" when Javascript is executed. Where part of your HTML code is mounted?
– Guto Xavier