Hi

I have a text box element in html.I need to call onfocus function of this text box from js file.

I using like this

document.formname.elementname.focus();

elementname is text box name
formname is its form name

This code works fine in IE but not working in mozilla..... suggest me anyone.

Instead of using
document.formname.elementname.focus();
use this instead
document.getElementById("elementname").focus();


It will sure work in all the browsers. Just because the name attribute sometimes creates problems,or you may have forget to give id or name or both attribute to(any/all) the elements in your page.

Try it once,hope it will hepl you.

Happy Coding...
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.