Solved

sizing a select

Posted on 2002-04-05
9
150 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 19

Accepted Solution

by:
DreamMaster earned 100 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 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