Retroity
Retroity

Reputation: 13

Bind multiple events to a function?

If I have searchbox.onsubmit = function(){ //Function here } and I wanted searchbtn.onclick to trigger the same function, how would I go about doing that?

Upvotes: 1

Views: 44

Answers (2)

Harsha Jayamanna
Harsha Jayamanna

Reputation: 2258

This will work too.

var myFunction = function() {
   alert("myfunc");
}

searchbox.addEventListener("submit", myFunction);
searchbtn.addEventListener("click", myFunction);

Upvotes: 0

jas7457
jas7457

Reputation: 1782

Have you tried...

function handleEvent(){
}

searchbox.onsubmit = handleEvent;
searchbtn.onclick = handleEvent;

Upvotes: 2

Related Questions