Page 1 of 1
CanFocus
Posted: Mon May 05, 2003 2:57 am
by []InTeR[]
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.
Posted: Mon May 05, 2003 10:25 am
by []InTeR[]
Or a other solution.....
Is this problem to big for the world?
Hrm, let kill javascript...........
Posted: Mon May 05, 2003 11:12 am
by volka
you might walk up the element hierarchy to see wether there is a parent element currently hidden.
Posted: Tue May 06, 2003 2:11 am
by []InTeR[]
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'.

not quite finished
Posted: Tue May 06, 2003 1:52 pm
by phpScott
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.
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>
phpScott
ps. If you do get it finished please psot it so I can use it.
Thanks
Posted: Tue May 06, 2003 5:13 pm
by []InTeR[]
Yes nice script,
but i don't know what object is 'hidden' my input box.
So that is the problem.
Posted: Tue May 06, 2003 5:57 pm
by Heavy
You can access almost any HTML element by supplying an id parameter:
Code: Select all
<div id="id1">
<input type="text" name="TextInput" id="myinputobj" value="testtext">
</div>
Then you can use following javascript to get the object:
Code: Select all
var obj = document.getElementById('id1')
Then, any property available to this object can be checked for with javascript.
For example:
Code: Select all
if(obj.style.visibility == 'visible'){
myinputobj.focus()
}
...which goes for its parents too, so if you don't know whether its DOM-parents are visible, just check them too:
Code: Select all
var obj = document.getElementById('id1')
var objmore = document.getElementById('anotherid')
if(obj.style.visibility == 'visible' && objmore.style.visibility == 'visible'){
myinputobj.focus()
}
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.
Posted: Wed May 07, 2003 2:14 am
by []InTeR[]
Okay,
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";
}
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.

Posted: Wed May 07, 2003 2:53 am
by Heavy
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:
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>
I don't know if I got you right, but now it is your turn.
See you.
Posted: Wed May 07, 2003 3:05 am
by []InTeR[]
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.
Posted: Wed May 07, 2003 3:45 am
by Heavy
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:
Code: Select all
<html>
<head>
<script language="JavaScript1.3" src="external-script.js"></script>
</head>
<body>
bla bla bla
</body>
external-script.js: