Results 1 to 3 of 3

Thread: Switch Content Script and focus();

  1. #1
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Switch Content Script and focus();

    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:

    Code:
    <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]

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You could pass the identifier for the text box as a third parameter to the expandcontent function:
    Code:
    <table onClick="expandcontent(this, 'sc1', document.myForm.myTextBox);">
    Then in the function add code to focus it only on expand (additions in red):
    Code:
    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()
    }
    }
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ah, beautiful, that works wonders!

    Thank you!!!

    [unintelligible]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •