473,772 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting style of dynamic options

I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?
Jul 23 '05 #1
9 2564
ne********@hotm ail.com wrote:
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?


500 what? Pixels?
And why no "el.text"?
Mick
Jul 23 '05 #2
ne********@hotm ail.com wrote in message news:<5b******* *************** ****@posting.go ogle.com>...
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?


el.style.height = "500px"; //tall option!
Jul 23 '05 #3
ne********@hotm ail.com wrote:
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?


You control the style of an option from the select element it's nested
inside. If you are trying to control the size of the option font, use
a style on the select:

<form...>
<select style="font-size: 12pt;">
<option ...>...</option>
...

Naturally you can also use a CSS class rather than an in-line style.

If you are trying to control the height of the box that the options are
displayed inside, use the "size" attribute of the select element:

<form...>
<select style="font-size: 12pt;" size="4">
<option ...>...</option>
...

"size" refers to the number of options displayed, so you may not want
to use 500.

More information can be found here:

<URL: http://www.w3.org/TR/html4/interact/forms.html#h-17.6>

Cheers, Rob.
Jul 23 '05 #4
RobG <rg***@iinet.ne t.auau> wrote in message news:<PN******* **********@news .optus.net.au>. ..
ne********@hotm ail.com wrote:
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?
You control the style of an option from the select element it's nested
inside. If you are trying to control the size of the option font, use
a style on the select:

<form...>
<select style="font-size: 12pt;">
<option ...>...</option>
...

Naturally you can also use a CSS class rather than an in-line style.

If you are trying to control the height of the box that the options are
displayed inside, use the "size" attribute of the select element:

<form...>
<select style="font-size: 12pt;" size="4">
<option ...>...</option>
...

"size" refers to the number of options displayed, so you may not want
to use 500.

More information can be found here:

<URL: http://www.w3.org/TR/html4/interact/forms.html#h-17.6>

Cheers, Rob.

RobG wrote
You control the style of an option from the select element it's nested
inside.


Only in Internet Explorer, where 'windowed' elements (like listboxes)
have limited exposure. More advanced CSS browsers allow styling of
Options like any other element, although some layout aspects,
naturally, pertain to the containing list rather than any specific
option.
Jul 23 '05 #5
RobB wrote:
RobG wrote
You control the style of an option from the select element it's nested
inside.

Only in Internet Explorer, where 'windowed' elements (like listboxes)
have limited exposure. More advanced CSS browsers allow styling of
Options like any other element, although some layout aspects,
naturally, pertain to the containing list rather than any specific
option.


Not just Explorer, Safari is the same (but I haven't tested the latest
version). I expect all the Geko-based browsers support styles on
options, perhaps someone can comment on Opera.

Below is some test code, try changing the height of option 11 to 20em -
additional space is added below option 25 - similarly if you make it
500px as the OP attempted.

A bit of testing in Firefox shows that whilst small heights (say
equivalent to 2 to 5 lines) work fine, large heights are not reliable
and results vary if options have different heights specified. Note
also that the option height affects the select height - even though
only 3 rows are supposed to show, the select is greatly expanded - I
guess that the select height is set to size x the largest line height
which can result in an overly extended select.

Given that the OP didn't see any effect of "height" in their browser,
it's likely that s/he isn't using one of the "more advanced CSS
browsers". And given the majority of web surfers use IE, it's best not
to depend on features it doesn't have.

To top it off, the difficulty of controlling the size of the select
element itself if options are given different heights introduces
apparent unreliability in the UI that users may not understand.

But it's an issue worth discussing - thanks for bringing it up. :-)

Rob.

*Play code follows:*

<form action="">
<select name="aSelect"
style="font-size: 10pt; font-family: sans-serif;" size="3">
<option value="opt1">op tion 1
<option value="opt2">op tion 2
<option value="opt3">op tion 3
<option value="opt4">op tion 4
<option value="opt5">op tion 5
<option value="opt6">op tion 6
<option value="opt7">op tion 7
<option value="opt8"
style="font-family: courier; font-weight: bold;">option 8
<option value="opt9"
style="font-weight: bold; height: 20px;">option 9
<option value="opt10">o ption 10
<option value="opt11"
style="font-weight: bold; height: 2em;">option 11
<option value="opt12">o ption 12
<option value="opt13">o ption 13
<option value="opt14">o ption 14
<option value="opt15">o ption 15
<option value="opt16">o ption 16
<option value="opt17">o ption 17
<option value="opt18">o ption 18
<option value="opt19">o ption 19
<option value="opt20">o ption 20
<option value="opt21">o ption 21
<option value="opt22">o ption 22
<option value="opt23">o ption 23
<option value="opt24">o ption 24
<option value="opt25">o ption 25
</select><br>
<input type="reset"><b r><br>
<input type="text" cols="10" name="aNum">
Enter a number from 1 to 25 and that option will be selected<br>
<input type="button" value="click me" onclick="
var x = this.form.aNum. value;
if (x > 0 && x < 26) {
this.form.aSele ct.options[x - 1].selected='true '
} else {
alert('From 1 to 25 please, ' + x + ' is out of bounds');
}
">
</form>
Jul 23 '05 #6
Mick White <mw******@roche ster.rr.com> wrote in message news:<e%******* *********@twist er.nyroc.rr.com >...
ne********@hotm ail.com wrote:
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?


500 what? Pixels?
And why no "el.text"?
Mick


500 anythings, i tried px, pt, % - none of them made any difference.
I was setting el.innerText, missed that out the code snippet. Sorry.
Jul 23 '05 #7
fe******@hotmai l.com (RobB) wrote in message news:<ab******* *************** ****@posting.go ogle.com>...
ne********@hotm ail.com wrote in message news:<5b******* *************** ****@posting.go ogle.com>...
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?


el.style.height = "500px"; //tall option!


tried this, but it doesn't seem to make any difference in IE.
Jul 23 '05 #8
RobG <rg***@iinet.ne t.auau> wrote in message news:<PN******* **********@news .optus.net.au>. ..
ne********@hotm ail.com wrote:
I'm dynamically adding options to a select list in javascript and i
need to be able to set the height of the option, but setting
style.height has not effect, I also tried style.pixelHeig ht but no
joy.

i'm doing something like this (:

var selectControl = document.getEle mentById('MySel ect');
var el = document.create Element('option ');
el.value = "some value";
el.style.height = "500";
selectControl.a ppendChild(el);
any ideas?


You control the style of an option from the select element it's nested
inside. If you are trying to control the size of the option font, use
a style on the select:

<form...>
<select style="font-size: 12pt;">
<option ...>...</option>
...

Naturally you can also use a CSS class rather than an in-line style.

If you are trying to control the height of the box that the options are
displayed inside, use the "size" attribute of the select element:

<form...>
<select style="font-size: 12pt;" size="4">
<option ...>...</option>
...

"size" refers to the number of options displayed, so you may not want
to use 500.

More information can be found here:

<URL: http://www.w3.org/TR/html4/interact/forms.html#h-17.6>

Cheers, Rob.


I don't want to set the font size of the select size. I want to set
the height of each option in the select, like line height.
Jul 23 '05 #9
RobG <rg***@iinet.ne t.auau> wrote in message news:<GQ******* **********@news .optus.net.au>. ..
RobB wrote:
RobG wrote
You control the style of an option from the select element it's nested
inside.

Only in Internet Explorer, where 'windowed' elements (like listboxes)
have limited exposure. More advanced CSS browsers allow styling of
Options like any other element, although some layout aspects,
naturally, pertain to the containing list rather than any specific
option.


Not just Explorer, Safari is the same (but I haven't tested the latest
version). I expect all the Geko-based browsers support styles on
options, perhaps someone can comment on Opera.

Below is some test code, try changing the height of option 11 to 20em -
additional space is added below option 25 - similarly if you make it
500px as the OP attempted.

A bit of testing in Firefox shows that whilst small heights (say
equivalent to 2 to 5 lines) work fine, large heights are not reliable
and results vary if options have different heights specified. Note
also that the option height affects the select height - even though
only 3 rows are supposed to show, the select is greatly expanded - I
guess that the select height is set to size x the largest line height
which can result in an overly extended select.

Given that the OP didn't see any effect of "height" in their browser,
it's likely that s/he isn't using one of the "more advanced CSS
browsers". And given the majority of web surfers use IE, it's best not
to depend on features it doesn't have.

To top it off, the difficulty of controlling the size of the select
element itself if options are given different heights introduces
apparent unreliability in the UI that users may not understand.

But it's an issue worth discussing - thanks for bringing it up. :-)

Rob.

*Play code follows:*

<form action="">
<select name="aSelect"
style="font-size: 10pt; font-family: sans-serif;" size="3">
<option value="opt1">op tion 1
<option value="opt2">op tion 2
<option value="opt3">op tion 3
<option value="opt4">op tion 4
<option value="opt5">op tion 5
<option value="opt6">op tion 6
<option value="opt7">op tion 7
<option value="opt8"
style="font-family: courier; font-weight: bold;">option 8
<option value="opt9"
style="font-weight: bold; height: 20px;">option 9
<option value="opt10">o ption 10
<option value="opt11"
style="font-weight: bold; height: 2em;">option 11
<option value="opt12">o ption 12
<option value="opt13">o ption 13
<option value="opt14">o ption 14
<option value="opt15">o ption 15
<option value="opt16">o ption 16
<option value="opt17">o ption 17
<option value="opt18">o ption 18
<option value="opt19">o ption 19
<option value="opt20">o ption 20
<option value="opt21">o ption 21
<option value="opt22">o ption 22
<option value="opt23">o ption 23
<option value="opt24">o ption 24
<option value="opt25">o ption 25
</select><br>
<input type="reset"><b r><br>
<input type="text" cols="10" name="aNum">
Enter a number from 1 to 25 and that option will be selected<br>
<input type="button" value="click me" onclick="
var x = this.form.aNum. value;
if (x > 0 && x < 26) {
this.form.aSele ct.options[x - 1].selected='true '
} else {
alert('From 1 to 25 please, ' + x + ' is out of bounds');
}
">
</form>


Thanks, that makes sense. So setting the height of option isn't
something that can be done in IE. And sure enough, testing my existing
code in Firefox works as expected, sadly it's for an internal web
application where only IE is supported.

Oh well, another feature dropped from the supported list.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
102937
by: Jeff Anderson | last post by:
Is there a style for a select option's "selected" color? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1 <OPTION>Test 2 <OPTION>Test 3 <OPTION>Test 4
3
3033
by: Max Weber | last post by:
Try to run the code below in a page. You will notice than when you switch the multiple attribute of the SELECT tag, only one option is displayed as selected although multiple options have ben created as selected. May somebody give me an explanation ? <input type="button" value="test" onclick="test()"/> <select name="tagSelect" style="width:100%"> </select>
4
1641
by: David | last post by:
Greeting All: Time to pick the collective brain cell again. I have a web page that adds options to a select box on the fly. What I need to do is set the onDblClick event the same way. I need to call a function when the user double clicks on anything in the list box. ANy help would be greatly appreciated. THanks
9
2127
by: Adam | last post by:
Hey, I'm trying to write a script with two standard drop down boxes. One contains days one contains the month. I want to update the options in the days box everytime the month is changed... i.e select August, and days are filled up to 31, select September and only 30. The part where I am having difficulty is that after the onChange event has triggered and I have checked what the new month is, filling the box with relevant values is...
4
2507
by: thomastk | last post by:
Hi, In the following script, I am trying to set selection to a select option element, that is newly created within the script. It works fine on IE installations on Windows 2000 and some XP machines. But on some XP machines, the selection doesn't happen and it defaults to the first element in the options array. Has anybody come across this problem ? Any known workarounds? Thanks Thomas.
1
6509
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
3
52250
by: Jason Carlton | last post by:
Is there a way to change the font-family and font-size for each individual option in a select menu? Something along the lines of: <select size="1"> <option style="font-family: Arial; font-size: 8px">One</option> <option style="font-family: Tahoma; font-size: 10px">Two</option> <option style="font-family: Verdana; font-size: 12px">Three</option> </select> I see that I can change the color using style="color: whatever", but
6
1965
by: Steve | last post by:
I have a div with two - three paragrahs in it. Each paragraph has its own inline style tag with its own font size setting. When I set the last paragraph's font size the font sizes for ALL of the paragraphs change. Why? How can I stop it? I.E>
1
2964
by: jmartmem | last post by:
Greetings, I have a nagging problem with client-side dynamic dependent list boxes that perhaps someone can help me troubleshoot. I have a form with a series of dynamic dependent list boxes. Making a selection from list/box A (Qtr) selects a fiscal quarter, which then refreshes the values in list/box B (Mth), which shows the 3 months in that fiscal quarter, which then refreshes the values in list/box C (MthDate), which returns the date...
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.