473,657 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setfocus to field inside tabs/pages

Hi,

I would like to set focus to a field in a form inside a tab page.
It is a multiple tabs under different divisions (eg: sc1,sc2,sc3,etc )

<div name='sc1'>
<form name='form1'>
<input name='myfield'>
</form>
</div>

Then I do this :

document.form1. myfield.focus()

It gives me error : can not move focus to the control because it is invisible,not enabled or of a type that can not accept focus

What is the correct command ?

Regards
Hoe
Jul 23 '05 #1
3 2654
Ivo
"tnhoe" <tn***@pc.jarin g.my> wrote

I would like to set focus to a field in a form inside a tab page.
It is a multiple tabs under different divisions (eg: sc1,sc2,sc3,etc )

<div name='sc1'>
<form name='form1'>
<input name='myfield'>
</form>
</div>

Then I do this :

document.form1. myfield.focus()

It gives me error : can not move focus to the control because it is
invisible,not enabled or of a type that can not accept focus

What is the correct command ?
You don't say the important thing about tabs: that they can be hidden. If
the form is inside a div that has a style rule like "display:no ne" or
"visibility:hid den", either literally or through a class or whatever, then
the form is hidden too, so the input element is hidden too and hidden
elements can by their very nature not receive focus!
document.form1. myfield.select( ) would throw the same error.
So you must check all parent elements for their visibility, or put the
focus() call in a try/catch block. It should not be hard to tell scriptwise
whether a tab is currently the one and only visible and active tab. A last
idea, to arrange your page to use overlapping tabs or moving tabs offscreen
rather than hidden tabs, would introduce other problems.

hth
ivo
Jul 23 '05 #2
Ivo,

Each tab will become active focus/display when mouseover.
How do I set focus to a field when the tab is active ?

This is the part I download somewhere :-

<style type="text/css">

#ddimagetabs{
}

#ddimagetabs a{
display:block;
text-decoration: none;
font: 12px Arial; /*tab font */
color: black; /*font color */
width: 86px; /*width of tab image */
height: 22px; /*height of tab image */
display:inline;
float: left;
margin-left: 4px; /*spacing between tabs */
padding-top: 4px; /*vertical offset of tab text from top of tab*/
background-image:url(bluet ab.jpg); /*URL to tab image */
background-repeat: no-repeat;
text-align: center;
}

#ddimagetabs a:hover, #ddimagetabs a.current{
background-image:url(bluet abover.jpg); /*URL to tab image onmouseover */
color: black;
}

#tabcontentcont ainer{
width:950px; /*width of 2nd level content*/
height:500px; /*height of 2nd level content. Set to largest's content height
to avoid jittering.*/
padding: 5px;
border: 1px solid blue;
}

..tabcontent{
display:none;
}

</style>

<script type="text/javascript">

/*************** *************** *************** **
* DD Tab Menu II script- © Dynamic Drive DHTML code library
(www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
*************** *************** *************** **/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:

var initialtab=[1,'sc1']

//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes

//Disable hyperlinks in 1st level tab images?
var disabletablinks =0 //0 for no (default), 1 for yes
////////Stop editting////////////////

var previoustab=""

if (turntosingle== 1)
document.write( '<style type="text/css">\n#tabcont entcontainer{di splay:
none;}\n</style>')

function expandcontent(c id, aobject){
if (disabletablink s==1)
aobject.onclick =new Function("retur n false")
if (document.getEl ementById && turntosingle==0 ){
highlighttab(ao bject)
if (previoustab!=" ")
document.getEle mentById(previo ustab).style.di splay="none"
document.getEle mentById(cid).s tyle.display="b lock"
previoustab=cid
}
}

function highlighttab(ao bject){
if (typeof tabobjlinks=="u ndefined")
collectddimaget abs()
for (i=0; i<tabobjlinks.l ength; i++)
tabobjlinks[i].className=""
aobject.classNa me="current"
}

function collectddimaget abs(){
var tabobj=document .getElementById ("ddimagetab s")
tabobjlinks=tab obj.getElements ByTagName("A")
}

function do_onload(){
collectddimaget abs()
expandcontent(i nitialtab[1], tabobjlinks[initialtab[0]-1])
}

if (window.addEven tListener)
window.addEvent Listener("load" , do_onload, false)
else if (window.attachE vent)
window.attachEv ent("onload", do_onload)
else if (document.getEl ementById)
window.onload=d o_onload

</script>
Regards
Hoe
Jul 23 '05 #3
tnhoe wrote:
Ivo,

Each tab will become active focus/display when mouseover.
How do I set focus to a field when the tab is active ?


You are using an A element with hover to change the colour of your tabs
to show which is 'active'.

Presumably you wish to add a mouseover event to make the body associated
with the tab visible when the mouse is over the tab. I prefer an
onclick event, but that's your choice - mouseover in this case is much
to 'busy' for my liking. Since you need a mouseover for the bodies to
be hidden and shown, you may as well ditch the A and hover and just use
plain divs. It also means you won't get any hover behaviour if
JavaScript is disabled (a good thing I think).

The script below adds a mouseover event to each tab to make the tab
'highlighted', set all the other tabs to 'not highlighted', hide all the
other bodies and show the body associated with the 'mouseover' tab.
Finally, set focus on the first text input of the first form in the
currently displayed body - this produces a non-critical error in
Firefox, there is no workaround that I am aware of - it isn't fatal,
just annoying if the JavaScript console is visible and set to display
errors.

For extra speed, an array is created and kept of references to the tabs
and associated bodies based on ids.

You need to make sure that if JavaScript is not enabled, the body of
each tab still shows (as per the example). Note that my CSS is pretty
ordinary, it's just there for the demo.
[...]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><ti tle>Show random matrix</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">

var aTabs = []; // Array of tab div element references
var aBods = []; // Array of body div element references

function initTabs() {
// Check required features are supported
if ( ! document.getEle mentsByTagName ) return;
// Get a collection of all divs
var divs = document.getEle mentsByTagName( 'div');
var d, i=0, j=divs.length;
// Add divs to body div or tab div array depending on id
while ( i<j ) {
d = divs[i];
i++;
if ( d.id ) {
if ( d.id.match( 'body_' ) ){
aBods.push(d);
d.className += ( i < 2 )? ' activeB':' inactiveB';
} else if ( d.id.match( 'tab_' ) ){
aTabs.push(d);
d.onmouseover = showBod;
d.className += ( i < 2 )? ' activeT':' inactiveT';
}
}
}
// Set 0 tab to shown
showBod( aTabs[0] );
}

function showBod( el ) {
var b, n, t;
if ( !el || !el.nodeName ) el = this;
var n = 'body_' + el.id.split('_' )[1];
var i = aBods.length;
while ( i-- ) {
b = aBods[i];
t = aTabs[i];
if ( n == b.id ) {
b.className = b.className.rep lace(/\binactiveB\b/,' activeB');
t.className = t.className.rep lace(/\binactiveT\b/,' activeT');
fieldFocus( b );
} else {
b.className = b.className.rep lace(/\bactiveB\b/,' inactiveB');
t.className = t.className.rep lace(/\bactiveT\b/,' inactiveT');
}
}
}

function fieldFocus( f ) {
f = f.getElementsBy TagName('form')[0];
var el, els = f.elements;
for ( var i=0, j=els.length; i<j; i++ ) {
el = els[i];
if ( 'text' == el.type && el.focus ) {
el.focus();
return;
}
}
}

</script>
<style type="text/css">
body { margin-top: 10px; padding: 0;}
..tabDiv {
position: relative;
float: left;
top: 0px;
height: 5ex;
width: 5em;
border-top: 2px solid #77777B;
border-left: 2px solid #77777B;
border-right: 2px solid #77777B;
margin: 0; padding: 0;
text-align: center;
line-height: 5ex;
}
..bodyDiv {
position: relative;
margin-top: 2px;
top: 5ex;
left: 0;
background-color: #ffffff;
border: 2px solid #77777B;
color: #000000;
z-index: 0;
}
..activeB { position: relative; display: block; }
..inactiveB { position: relative; display: none; }
..activeT {
background-color: #FFFFFF; z-index: 20;
border-bottom: 2px solid #ffffff;
}
..inactiveT {
background-color: #C0C0C0; z-index: 10;
border-bottom: 2px solid #77777B;
}

</style>
</head><body onload="initTab s();">
<div id="tab_0" class="tabDiv">
Tab 0
</div>
<div id="tab_1" class="tabDiv">
Tab 1
</div>
<div id="tab_2" class="tabDiv">
Tab 2
</div>
<!-- content for body 0 -->
<div id="body_0" class="bodyDiv" >
<h1>Here is the content for body 0</h1>
<form name="body_0_fo rm" action="">
<input type="text" name="input_0_1 "><br>
<select>
<option>opt 0
<option>opt 1
<option>opt 2
</select>
<input type="reset">&n bsp;
<input type="submit">
</form>
</div>
<!-- content for body 1 -->
<div id="body_1" class="bodyDiv" >
<h1>Here is the content for body 1</h1>
<form name="body_1_fo rm" action="">
<input type="text" name="input_1_1 "><br>
<input type="text" name="input_1_2 "><br>
<input type="text" name="input_1_3 "><br>
<input type="reset">&n bsp;
<input type="submit">
</form>
</div>
<!-- content for body 2 -->
<div id="body_2" class="bodyDiv" >
<h1>Here is the content for body 2</h1>
<form name="body_2_fo rm" action="">
<input type="text" name="input_2_1 "><br>
<input type="text" name="input_2_2 "><br>
<select>
<option>opt 0
<option>opt 1
<option>opt 2
</select>
<input type="text" name="input_2_3 "><br>
<input type="reset">&n bsp;
<input type="submit">
</form>
</div>

</body></html>

--
Rob
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
27586
by: Ben Smeets | last post by:
Hi folks, Have been trying to figure out a solution for the following problem by reading lots of threads here, but doesn't work out. Hope someone can help me. I have a parent window which opens a popup window (child). What i would like to do, is to be abke to keep surfing to other pages in the parent and after (lets say) a couple of new pages, still be able to say "child.setFocus()";
3
2492
by: Eric | last post by:
Hi, I wrote a Sub to run "Find and Replace" menu command on Access 2000. It worked fine except SetFocus didn't work. It changed position from time to time. I need the Focus always set at field Here is the Sub: 'Find What: Need Code to SetFocus here??? 'Look In: current field only 'Match: Any Part of Field
2
2395
by: Johann Blake | last post by:
The following is a bug I have discovered using tab pages and threads and I am looking for a workaround. Create a new Windows Forms application and add a tab control with two tab pages. Add a label to each tab page. On the first tab page add a button. When the button is pressed the code behind the button creates a thread and starts that thread. The only thing that the thread is to do is to switch from the first tab page to the 2nd tab...
10
1914
by: dale zhang | last post by:
Hi, I saw the post here about setfocus. But they are for web form. Web control page HTML does not have form1. the Jscript there does not work here. My question is how to set focus to the text box in web control page?
4
9674
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1. RegisterStartupScript("sf","<scriptlanguage='javascript'>document.form.MyControlID.focus();</script>"); 2. Andy Smith's FirstFocus control from http://www.metabuilders.com/tools/FirstFocus.aspx
4
3314
by: AA Arens | last post by:
I use SetFocus to jump from one field to another. That works fine. But one of the focussed fields has default text and this text is selected and the cursor is on the left of it. How to have the curosr positioned at the right of the default (or filled) text? Bart (v 2003)
3
6673
by: Jim Devenish | last post by:
In my application vehicles arrive and depart from a workshop. The ArrivalDate and the HandoverDate are each entered. Sometimes the person who should enter the arrival date forgets to do so. When the vehicle is handed over to the customer and the HandoverDate is entered I wish to warn about the possibly missing ArrivalDate. In the BeforeUpdate event of HandoverDate I have: Private Sub HandoverDate_BeforeUpdate(Cancel As Integer) If...
0
1539
by: srinivasarao yarru | last post by:
hi sir, in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field :- Description about this code:- Sex field is one combo box in two options male-1;female-2 IND_APPL is one combo box here options are applicable-1;not applicable-0 CODE:-
3
3468
by: srinivasarao yarru | last post by:
hi in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field (this is my problem please give proper gidence for this problem) :- Description about this code:- Sex field is one combo box in two options male-1;female-2 IND_APPL is one combo box here options are applicable-1;not applicable-0
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.