Solved

sizing a select

Posted on 2002-04-05
9
149 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
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 is …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now