Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old July 5th, 2007, 10:40 PM   #1
New Member
 

Join Date: Jul 2007
Location: KUALA LUMPUR
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 AJAY KUMAR is on a distinguished road
Is it possible to set the FOCUS() dynamically with javascript

hi,

Code:
<html>
<head>
<script language="JavaScript">
 
 function checkme(strVal){
 var id=strVal;
            alert(id);
     //document.all[strVal].focus();---->(IE) FOR IE it is working but not working for mozilla firefox
     document.forms[strVal].focus(); //(FIREFOX)
 }
</script>
</head>
<body>
<form>
NAME..<input type="text" name="empName" size="5" maxlength="4" onChange="checkme(this.value)"/><br>
ID....<input type="text" name="id" value=""/><br>
DEPT..<input type="text" name="dept" value=""/><br>
</form>
</body>
</html>

Last edited by AJAY KUMAR; July 6th, 2007 at 12:35 AM..
AJAY KUMAR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 7th, 2007, 11:06 AM   #2
Reputable Member
 

Join Date: Dec 2005
Location: U.S.A.
Posts: 156
Thanks: 0
Thanked 4 Times in 4 Posts
Rep Altering Power: 0 ScottR is on a distinguished road
Re: Is it possible to set the FOCUS() dynamically with javascript

Correct me if I'm wrong, but it appears that you are trying to set the focus in a textfield that maybe a username or something along those lines. IMO the best thing to do would be to use getElementById and set the focus that way. You could put it in a function and use the onload event handler in your body tag.

Code:
function selectField() {
document.getElementById("id of testfield").focus()
}
Code:
<body onload="selectField()">
Good Luck,
Scott
__________________
Web Design and Development
ScottR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 8th, 2007, 11:29 PM   #3
New Member
 

Join Date: Jul 2007
Location: KUALA LUMPUR
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 AJAY KUMAR is on a distinguished road
Re: Is it possible to set the FOCUS() dynamically with javascript

hello firends,
finally i got the solution. As u can see my coding in the top of the page, there i have used the following code to focus it.

Code:
document.forms[0][strVal].focus();
Thank you for ur valuable support,
Ajay.
AJAY KUMAR is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
focus


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I focus on one area of website building molla How is this done? 4 December 17th, 2007 07:59 AM
Cursor focus getting lost in IE kallol HTML, XHTML and CSS 5 April 10th, 2007 04:09 AM
focus() onLoad Jaken Veina JavaScript 1 April 22nd, 2006 01:34 PM
text box focus Prakashcee Flash and ActionScript 2 December 6th, 2005 04:35 AM


Search Engine Optimization by vBSEO 3.2.0 RC8