PDA

View Full Version : Switch Content Script and focus();



unintelligible
08-05-2005, 07:22 PM
Hello,

I am using the wonderful Switch Content script here from DD for my company intranet. I'm essentially expanding and collapsing tables with text boxes in them. What I have been trying to do is to send a focus() call to the text box within the <div> tag that I am expanding to automatically set the focus to that box. This is how I am doing it:


<table onClick="expandcontent(this, 'sc1'); document.myForm.myTextBox.focus();">

This works just fine when the header is expanded, but once it becomes collapsed/invisible, the element is no longer detectable through JS on the page, so it throws a script error.

Does anyone know where I might be able to add my focus call (even if it's just a matter of detecting which scX was clicked and focusing the appropriate text box through an if/elseif or whatever) in the DD code?

Thanks!
[unintelligible]

jscheuer1
08-05-2005, 08:04 PM
You could pass the identifier for the text box as a third parameter to the expandcontent function:

<table onClick="expandcontent(this, 'sc1', document.myForm.myTextBox);">Then in the function add code to focus it only on expand (additions in red):

function expandcontent(curobj, cid, formIdent){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (document.getElementById(cid).style.display=="block"&&formIdent!==undefined)
formIdent.focus();
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

unintelligible
08-05-2005, 08:30 PM
Ah, beautiful, that works wonders!

Thank you!!! :D

[unintelligible]