faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

How do i set the width of a 'showmore'button to the width of a dynamically extending dropdown list ?

Apr 8th, 2008 19:16
ha mo, Dave Clark, Shadul Narang,


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shadul,
     A definitive answer depends upon just what you mean.  Thus, 
making some assumptions about what you mean:
function SetButtonWidth()
{
    var sel = document.forms['formName'].elements['selectName'];
    var wdt = sel.offsetWidth;
    var btn = document.forms['formName'].elements['buttonName'];
    btn.style.width = wdt+"px";
}
     Now, to make the button expand each time the select element 
expands, simply execute that function on a timer just before exiting 
from the function which adds options to the select element.  For 
example:
    window.setTimeout("SetButtonWidth()", 200);
The reason for executing this function on a timer is because the 
browser doesn't render the new width of the select element until all 
user events have ended.
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com