[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

get the width of a drop down list

Posted on 2006-04-06
3
Medium Priority
?
636 Views
Last Modified: 2010-04-07
I am trying to get the width of a drop down list. I know that the drop down list width will be equivilent to the longest drop down value . Is there a quicker way to determine that length without looping through all values contained in the drop down to find out the longest drop down value.

I am trying document.forms[0].DropDownField.width but this gives me undefined.

Please help...
0
Comment
Question by:Knowledge-Dimension
3 Comments
 
LVL 7

Expert Comment

by:cstsang
ID: 16398440
have you try:
document.forms[0].DropDownField.style.width
0
 
LVL 9

Accepted Solution

by:
smaccari earned 2000 total points
ID: 16398501
The style.width will return only if it was fixed in style attribute or class.
This will work better:

documents.forms[0].elements["DropDownField"].clientWidth
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 16402024
Access the offsetWidth parameter
Here is an example. Does not matter the how it has been set (auto or style.width);

Good Luck.

 
<html>
<head>
<title>Width of Combo Box</title>
</head>
<body>
<form name="form1">
<select name="sel1">
      <option value="v1">Option 1 Value 1
      <option value="v2">Option 2 Value 2
</select>
<script language="javascript">

alert (document.form1.sel1.offsetWidth);
</script>
</body>
</html>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question