Un-disabling submit button via JavaScript not working ejs

I must be being stupid. This should work right? I am trying to undisable the submit button of the form when the user types in the same as the ejs variable project.name, but I get the error Cannot read property 'value' of null Does this need to be ajax to be real-time or something? If so, I can do that instead

if(document.getElementById("monitorname").value == '<%=project.name%>'){ 
document.getElementById("deletesubmit").disabled = false;
}

I would be very grateful if someone could help me figure this out
Eddie

You could try something like this:

if (document.getElementById("monitorname").value.trim().toLowerCase() == '<%=project.name%>'.trim().toLowerCase()){ 
  document.getElementById("deletesubmit").disabled = false;
}

EDIT: Where is the if satement placed exactly? Are you checking on user input?

Yes, I am checking user input, that’s why I thought I might need to use Ajax. I tried moving the script tags around to see if it was that. Is there a specific place I should put it? Your code didn’t fix the error :frowning:
Thanks for trying to help! :slight_smile:

Can I have an invite to the project?

Another good way to debug it is adding console.log(document.getElementById("monitorname").value.trim().toLowerCase(), '<%=project.name%>'.trim().toLowerCase()) and check the console on client-side.

Yay! Got it working with this code:

$('#monitorname').keyup(function(){
if ($("#monitorname").val() == '<%=project.name%>'){ 
$("#deletesubmit").prop('disabled', false);
}});

Thanks for the help! :slight_smile:

jquery :face_vomiting:

2 Likes

It works so I ain’t complaining :joy:

1 Like

Alright :joy:   

2 Likes