?
Solved

sizing a select

Posted on 2002-04-05
9
Medium Priority
?
157 Views
Last Modified: 2010-04-09
I have this HTML code :

<TABLE>
 <TR>
  <TD BGCOLOR='#28A7F6' ALIGN='CENTER'>
    Aspect
  </TD>
</TR>
 <TR>
  <TD ALIGN='CENTER'>
   <select name=servicesPossibles1 size=3>
    <option>A</option>
    <option>B</option>
    <option>C</option>
   </select>
  </TD>
 </TR>
</TABLE>

(in fact, it's dynamic code).
It shows a title with a select. My problem is :
I don't want my select to be shorter than the title (the first cell of the table).
How do you set the width of the selct to be the one of the cell ?
0
Comment
Question by:seguret
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:svd2002
ID: 6920490
1. Let the id of the cell be "c1" whose width is to be assigned to <SELECT>
2. Let the id of the <SELECT> be "s1"

Write a function at the client side:
<SCRIPT LANGUAGE=javascript>
<!--
     function f()
     {
          s1.style.width = c1.clientWidth;
     }
//-->

This function can be called at the onLoad event of the <BODY>
0
 
LVL 2

Expert Comment

by:svd2002
ID: 6920494
1. Let the id of the cell be "c1" whose width is to be assigned to <SELECT>
2. Let the id of the <SELECT> be "s1"

Write a function at the client side:
<SCRIPT LANGUAGE=javascript>
<!--
     function f()
     {
          s1.style.width = c1.clientWidth;
     }
//-->

This function can be called at the onLoad event of the <BODY>
0
 
LVL 2

Expert Comment

by:svd2002
ID: 6920516
1. Let the id of the cell be "c1" whose width is to be assigned to <SELECT>
2. Let the id of the <SELECT> be "s1"

Write a function at the client side:
<SCRIPT LANGUAGE=javascript>
<!--
     function f()
     {
          s1.style.width = c1.clientWidth;
     }
//-->

This function can be called at the onLoad event of the <BODY>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
DreamMaster earned 300 total points
ID: 6920529
<select name="servicesPossibles1" width="20" style="width:30px;">

The first width should work for netscape...the style version works for Internet Explorer....

There is however no solid way to keep the select that size...because if any of the options is wider then the size you provided...Netscape will stretch it to the longest item...

Max.
0
 
LVL 4

Author Comment

by:seguret
ID: 6920547
That doesn't work : in fact, I cannot eve access to c1.clientWidth : the following code does nothing :
alert(c1.clientWidth);
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 6920567
Yes Max. is right on; you need to use css to widen your select box; thats the only way;

but just to ensure that all comes in your can change the font and size;

<select name="servicesPossibles1" width="20" style="width:30px; font-family:verdana; font-size:10px; letter-spacing:0px;word-spacing:0px;">

lexxwern
0
 
LVL 4

Author Comment

by:seguret
ID: 6920570
Thanx Maks, it works.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6920577
You're welcome sequret...

But if it worked....why the Grade B?

Max.

"Max is like a dream which glides in and out of the dark corners of Experts-Exchange like the early morning mist in a river delta..."

-Netminder-
0
 
LVL 2

Expert Comment

by:svd2002
ID: 6920588
if you cannot get the object with id "c1", try the following:
alert(document.getElementById("c1").clientWidth);
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

850 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