CanFocus
Moderator: General Moderators
CanFocus
I hava a small javascript function that set's a focus to a text-input field.
Now here comes the problem, this field can be 'hidden' by a stylesheet in a div. And you can't focus something when it's hidden.
I can't resolve the div, or know when he is hidden.
(Way of programming, it' a genarel script)
So a'm looking for a function like inputbox.canFocus();
But i'm lacking of finding it.
Now here comes the problem, this field can be 'hidden' by a stylesheet in a div. And you can't focus something when it's hidden.
I can't resolve the div, or know when he is hidden.
(Way of programming, it' a genarel script)
So a'm looking for a function like inputbox.canFocus();
But i'm lacking of finding it.
I'm not a javascript herro, but is there something like var_dump?
i can't find it...
But, the 1 'pointer' to a parent that I use is
boxname.form.tabIndex[boxname.tabIndex].focus();
But then if the next element is a hidden form it gives a error.
'Can't focus'.
Nice, so I check if this form element is a hidden.
if(formpie.elements[t1].type=='text'){
But now is the big problem.
What if there is a table,div or a other ellement around the form element.
That's hidden. (style="display: none").
And javascript is back again, 'Can't focus'.
i can't find it...
But, the 1 'pointer' to a parent that I use is
boxname.form.tabIndex[boxname.tabIndex].focus();
But then if the next element is a hidden form it gives a error.
'Can't focus'.
Nice, so I check if this form element is a hidden.
if(formpie.elements[t1].type=='text'){
But now is the big problem.
What if there is a table,div or a other ellement around the form element.
That's hidden. (style="display: none").
And javascript is back again, 'Can't focus'.
not quite finished
Here is a script that I have been working on. It is not quite finished as it was just for fun. It does almost work so if you want to finish playing with it go ahead.
phpScott
ps. If you do get it finished please psot it so I can use it.
Thanks
Code: Select all
<HTML>
<HEAD>
<title>combo box</title>
<script language="javascript">
function toggleInput(p_targ, p_status)
{
element=document.getElementById("comboList").value;
alert("element is " + element);
if(document.getElementById("comboList").style.visibility == 'visible')
{
alert("false");
document.getElementById("comboList").style.visibility='visible';
document.getElementById('comboText').style.visibility='hidden';
}
if(document.combo1.comboList.style.visibility=='hidden')
{
alert("true");
document.getElementById('comboText').style.visibility='visible';
document.getElementById('comboList').style.visibility='hidden';
}
}
</script>
</HEAD>
<BODY>
<FORM name="combo1" id="combo1">
<TABLE>
<TR>
<TD>
this is a combo box test
</TD>
<TD name="switch" id="switch">
<SELECT name='comboList' id='comboList'>
<OPTION value='1'>one</OPTION>
<OPTION value='2'>two</OPTION>
<OPTION value='3'>three</OPTION>
<OPTION value='4'>fout</OPTION>
<OPTION value='5'>five</OPTION>
<OPTION value='6'>six</OPTION>
</SELECT>
<input type="text" name="comboText" id="comboText" value="" />
</TD>
<TD>
<INPUT TYPE='CHECKBOX' name='switch1' value='1' align='middle' id='switch1' onClick='toggleInput(1,2)' />
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>ps. If you do get it finished please psot it so I can use it.
Thanks
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
You can access almost any HTML element by supplying an id parameter:
Then you can use following javascript to get the object:
Then, any property available to this object can be checked for with javascript.
For example:
...which goes for its parents too, so if you don't know whether its DOM-parents are visible, just check them too:
Since you havent posted the core of your page, we can't specifically help you out. But I suggest you poke around in the Netscape Devedge resources to find your way out. On the right, you have some links to useful information. You could try install Mozilla if you want a browser with some developer touch. It has javascript debugger and DOM inspector by default. Those tools (at least the debugger) are available for Netscape7 too.
Code: Select all
<div id="id1">
<input type="text" name="TextInput" id="myinputobj" value="testtext">
</div>Code: Select all
var obj = document.getElementById('id1')For example:
Code: Select all
if(obj.style.visibility == 'visible'){
myinputobj.focus()
}Code: Select all
var obj = document.getElementById('id1')
var objmore = document.getElementById('anotherid')
if(obj.style.visibility == 'visible' && objmore.style.visibility == 'visible'){
myinputobj.focus()
}Okay,
Let's parse some code
This is the part what's buggin me.
Now this is called by a gaint script that controles a fancy pulldown.
What reads a js array for his information, with id's.
To use this i have 2 fields, one that controls the pulldown (autocomplete,search,select, and show the selected).
And one with the same id as the first one, but extended with _id. This is the value I use in the database.
He skips the hidden _id field, but sometimes the next pulldown or open textfield is hidden by a, div.
I can't find out, what de id is of that div because it's a default script.
PS: If somebody wan't a demo, i can set one up.
Let's parse some code
This is the part what's buggin me.
Code: Select all
function change_box(id,what,what_id)
{
box = findDOM(id,0);
for(var i = 0;i < box.form.elements.length;i++){
box.form.elementsїi].tabIndex = i;
}
for(var i = 1;i < 6;i++){
if(box.form.elementsїbox.tabIndex+i].type=='text'){
// alert(box.form.elementsїbox.tabIndex+i].CanFocus);
// box.form.elementsїbox.tabIndex+i].focus();
i = 777;
}
}
box.value = what;
box_id = findDOM(id + '_id',0);
box_id.value = what_id;
resultdiv = document.getElementById('PULLDOWN');
resultdiv.style.visibility = "hidden";
}What reads a js array for his information, with id's.
To use this i have 2 fields, one that controls the pulldown (autocomplete,search,select, and show the selected).
And one with the same id as the first one, but extended with _id. This is the value I use in the database.
He skips the hidden _id field, but sometimes the next pulldown or open textfield is hidden by a, div.
I can't find out, what de id is of that div because it's a default script.
PS: If somebody wan't a demo, i can set one up.
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
Do you mean that you don't know the ID value of the DIV?
You say it is a default script. I don't quite understand what you mean.
Are you javascripting some page you don't have permission to change?
However, if you have control of that page you could do something like:
Take the parent IDs of an element into the ID definition of another element:
I don't know if I got you right, but now it is your turn.
See you.
You say it is a default script. I don't quite understand what you mean.
Are you javascripting some page you don't have permission to change?
However, if you have control of that page you could do something like:
Take the parent IDs of an element into the ID definition of another element:
Code: Select all
<div id="12">
<div id="12,31">
<div id="12,31,41">
<div id="12,31,41,16">
If you here know the ID, you can reach its parent by stripping the last "," and whatever behind it out.
</div>
</div>
<div id="12,31,48">
</div>
</div>
</div>See you.
I can edit the page, but then i have to edit 10's of pages.
And 100's of the boxes.
I don't want to change my html source
.
And the script seposed to work @ all times. This is the only freaking problem. (total js script is 380 lines).
It worked fine, only tab'ing trou the form's gives 'errors'.
The foces is steeled by the window object. So i want to give the focus to the next field.
And 100's of the boxes.
I don't want to change my html source
And the script seposed to work @ all times. This is the only freaking problem. (total js script is 380 lines).
It worked fine, only tab'ing trou the form's gives 'errors'.
The foces is steeled by the window object. So i want to give the focus to the next field.
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
If the pages are generated with PHP, you can functionalise that part of the pages with a PHP function that writes that critical part. Thus, you wouldn't have to rewrite all of those pages every time you want to change them.
Otherwise, Maybe the server can do some server side including, SSI.
If the JS-code is similar among the pages you could have the JS-functions externally defined:
page.html:
external-script.js:
Otherwise, Maybe the server can do some server side including, SSI.
If the JS-code is similar among the pages you could have the JS-functions externally defined:
page.html:
Code: Select all
<html>
<head>
<script language="JavaScript1.3" src="external-script.js"></script>
</head>
<body>
bla bla bla
</body>Code: Select all
//Javascript code