1

I am trying to call function when onfocus event occur in input field but its gives error that

function is not defined at htmlinputelement.onfocus
HTML:

<input type="text" class="form-control" onFocus="forFocus(this);" id="name" aria-describedby="emailHelp" placeholder="Enter Name">
Javscript function:

function forFocus(element){ console.log('here on focus is called now', element); } image of error which occure


Please help link http://jsfiddle.net/7gxnr7cb/18/

aashir khan
  • 598
  • 3
  • 7
  • 20
  • can't replicate with the given info. it just works. – Redu Sep 09 '17 at 07:37
  • You need to provide a [mcve]. You've failed on the "Complete" and "Verifiable" parts of that. – Quentin Sep 09 '17 at 07:40
  • @Quentin http://jsfiddle.net/7gxnr7cb/11/ – aashir khan Sep 09 '17 at 16:06
  • @Redu http://jsfiddle.net/7gxnr7cb/18/ check this – aashir khan Sep 09 '17 at 16:14
  • @aashir khan it doesn't work since you give the callback name inline and while html is parsed the function is undefined. So you best chose how JS is loaded from JS window top right menu of jsfiddle. Make sure that No Wrap - in or No Wrap - in is selected.. – Redu Sep 09 '17 at 16:43
  • @aashirkhan — You're supposed to put the [mcve] **in the question**. Don't host it elsewhere and just link to it. – Quentin Sep 10 '17 at 08:40
  • Also: Duplicate question: https://stackoverflow.com/questions/7043649/why-does-this-simple-jsfiddle-not-work – Quentin Sep 10 '17 at 08:41

1 Answers1

-1
<script>
function func1() {
    console.log('func1');    
}
</script>

<input type="text" id="foo" onfocus="func1()">

see example

Faizan
  • 1,132
  • 2
  • 12
  • 23