Solved

sizing a select

Posted on 2002-04-05
9
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

728 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