Javascript not calling IE9

I created a text box and wrote onfocus="getFocus()"

Now I wrote a function in javascript

function getFocus()

        {
            alert('Hello I Got Focus !!');
        }

The problem in IE8 works fine, but in IE9 the warning does not appear. Can anyone say what is wrong with the code?

I also tried

txtAmt.Attributes.Add("onfocus","getFocus()")

but still it didn’t work

I tried too

txtAmt.Attributes.Add("onfocus","javascript:getFocus();")

Now I'm worried .. what to do ??

+5
source share
4 answers

Open the IE Developer Tool (F12) after the page loads.

Check browser mode: and document mode:

Try setting browser mode to IE9 and document mode to IE9 standards.

Now try again and see if this works.

0
source

onFocusshould be rewritten as onfocus = "getFocus()".

, IE9 , , Javascript IE9.:)

+2

try javascript tag:

txtAmt.Attributes.Add ("OnFocus", "JavaScript: GetFocus ();")

  • javascript does not work if there is an error on the page. Check for errors by enabling javascript debugging.
  • Some older jquery versions are not supported in ie9 (version lower than 1.4.1)
+2
source

Your code seems great, have you tried checking IE security settings?

if you go

 Internet Options > Security > Custom level > 

 Make sure Active Scripting is not set to Disabled
+1
source

All Articles