Skip to content
Advertisement

Attempting to make enter button ‘clickable’

I want to make a ‘search’ button clickable upon clicking enter.

This is my html:

JavaScript

This is the JavaScript I am using:

JavaScript

I am however getting an error

‘Uncaught TypeError:Cannot call method click of nul’

Advice perhaps on why I get this error and is there a better alternative at achieving this?

Advertisement

Answer

are those runat="server" required? you get the error because when searchKeyPress gets called, your button doesn’t exist (yet). Either it’s being triggered before DOMContentLoaded, or asp.net is doing funky things with your button, keeping it out of the DOM entirely.

Also some general JavaScript tips:

JavaScript
Advertisement