473,624 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE/XP Problem setting option element to selected

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.
=============== =============== =====

<HTML>
<HEAD>
<META NAME="GENERATOR " Content="Micros oft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<P><INPUT id=text1 name=text1 onchange="javas cript:mytesting (this);">
<SELECT id=select1 style="WIDTH: 264px" name=select1>
<OPTION selected value="testing 1">testing 1</OPTION>
<OPTION value="testing 2">testing 2</OPTION>
<OPTION value="testing 3">testing 3</OPTION>
<OPTION value="testing 4">testing 4</OPTION>
<OPTION value="testing 5">testing 5</OPTION>
</SELECT><INPUT id=button1 type=button value="delect new added"
name=button1></P>
</BODY>
</HTML>
<script language="JavaS cript" >
function mytesting()
{
var fsDropDown = document.getEle mentById("selec t1");
if (fsDropDown !=null) {
var tempFS = fsDropDown.valu e;
//var selIdx = fsDropDown.sele ctedIndex;
var opt = document.create Element("OPTION ");
fsDropDown.opti ons.add(opt);
tempFS = tempFS+"*";
opt.innerText = tempFS;
opt.value = tempFS;
//opt.selected = true;

fsDropDown.opti ons[fsDropDown.opti ons.length-1].selected=true;
fsDropDown.sele ctedIndex = fsDropDown.opti ons.length-1;
}
}
</script>

Sep 1 '05 #1
4 2496
th******@hotmai l.com wrote:
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.
=============== =============== =====

<HTML>
<HEAD>
<META NAME="GENERATOR " Content="Micros oft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<P><INPUT id=text1 name=text1 onchange="javas cript:mytesting (this);">
<SELECT id=select1 style="WIDTH: 264px" name=select1>
<OPTION selected value="testing 1">testing 1</OPTION>
<OPTION value="testing 2">testing 2</OPTION>
<OPTION value="testing 3">testing 3</OPTION>
<OPTION value="testing 4">testing 4</OPTION>
<OPTION value="testing 5">testing 5</OPTION>
</SELECT><INPUT id=button1 type=button value="delect new added"
name=button1></P>
</BODY>
</HTML>
<script language="JavaS cript" >
function mytesting()
{
var fsDropDown = document.getEle mentById("selec t1");
if (fsDropDown !=null) {
var tempFS = fsDropDown.valu e;
//var selIdx = fsDropDown.sele ctedIndex;
var opt = document.create Element("OPTION ");
fsDropDown.opti ons.add(opt);
tempFS = tempFS+"*";
opt.innerText = tempFS;
opt.value = tempFS;
//opt.selected = true;

fsDropDown.opti ons[fsDropDown.opti ons.length-1].selected=true;
fsDropDown.sele ctedIndex = fsDropDown.opti ons.length-1;
}
}
</script>


IE has problems with options. To set all the properties on one go, use
something like:

var opt = new Option( text, value, defaultSelected , currentSelected );

where:
text is the option text as a string,
value is the option value as a string,
defaultSelected is a boolean (true or false),
currentSelected is a boolean (true or false),

There is a thread worth reading here:

<URL:http://groups.google.c o.uk/group/comp.lang.javas cript/browse_frm/thread/f1037605dfb1a9c 0/07f4f9df6cd3cdc 1?q=new+option( +value+text&rnu m=20&hl=en#07f4 f9df6cd3cdc1>


--
Rob
Sep 1 '05 #2
ASM
th******@hotmai l.com wrote:
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?
see there :
<http://aliasdmc.free.f r/dom_javascript_ html/javascript_html _select_add.htm l>

and see also bellow old JS that works
<HTML>
<HEAD>
<META NAME="GENERATOR " Content="Micros oft Visual Studio 6.0">
ha ! ben bravo !
<TITLE></TITLE>
<script type="text/javascript">
function mytesting()
{
var fsDropDown = document.getEle mentById("selec t1");
if (fsDropDown !=null) {
var tempFS = fsDropDown.opti ons[fsDropDown.sele ctedIndex].value;
fsDropDown.leng th++;
var opt = fsDropDown.opti ons[fsDropDown.leng th-1]
opt.value = opt.text = tempFS = tempFS+"*";
opt.selected = 'selected';
if(document.all ) opt.selected = true;
}
}
</script>
</HEAD>
<BODY>

<P><INPUT id=text1 name=text1 onchange="javas cript:mytesting (this);">
<SELECT id=select1 style="WIDTH: 264px" name=select1>
<OPTION selected value="testing 1">testing 1</OPTION>
<OPTION value="testing 2">testing 2</OPTION>
<OPTION value="testing 3">testing 3</OPTION>
<OPTION value="testing 4">testing 4</OPTION>
<OPTION value="testing 5">testing 5</OPTION>
</SELECT><INPUT id=button1 type=button value="delect new added"
name=button1></P>

</BODY>
</HTML>


--
Stephane Moriaux et son [moins] vieux Mac
Sep 1 '05 #3
ASM wrote:
[...]

var tempFS = fsDropDown.opti ons[fsDropDown.sele ctedIndex].value;
fsDropDown.leng th++;
var opt = fsDropDown.opti ons[fsDropDown.leng th-1]
opt.value = opt.text = tempFS = tempFS+"*";
opt.selected = 'selected';
if(document.all ) opt.selected = true;

var tempFS = fsDropDown.opti ons[fsDropDown.sele ctedIndex].value;
var newOpt = new Option( tempFS+'*', tempFS+'*', false, true );
fsDropDown.opti ons[fsDropDown.opti ons.length] = newOpt;

[...]

--
Rob
Sep 1 '05 #4
Tried both the suggestions, but the problem is still reproducible on
the problem XP machines, as with the js/html I had posted.

Thanks
Thomas.

Sep 1 '05 #5

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

Similar topics

9
2551
by: netclectic | last post by:
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.pixelHeight but no joy. i'm doing something like this (: var selectControl = document.getElementById('MySelect'); var el = document.createElement('option'); el.value = "some value";
4
6294
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
2
3782
by: gabon | last post by:
I'm creating a select entirely through JavaScript and very strangely IE doesn't show the text in the option elements. Here part of the code: this.form_country=document.createElement("select"); var option; for(var i=0; i<arr.length; i++){ option=document.createElement("option"); option.value=arr.code;
7
1941
by: Stefan Mueller | last post by:
I choose 'Entry 4' and click then on the button 'Set' to set the index to 'Entry 2'. If you press now the cursor down key 'Entry 5' instead of 'Entry 3' shows up with Mozilla Firefox. With Internet Explorer and Opera it works fine; 'Entry 3' shows up. Is this a bug within Mozilla Firefox or do I have any possibility to change this wrong behavior? Stefan ========================
1
3674
by: Brent | last post by:
I thought this would be a problem easily fixed in a simple Google search, but I'm having a hard time finding a solution. I simply need a way to set the value of an option element from an option value provided in an AJAX response. I'm doing just fine with text boxes and div elements, but the option value eludes me. I've tried the following: document.editForm.co_status.selected =...
2
3647
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code /////////////////////////////////////////////////////////////////////////////////////// <form action="whatever.php" method="post"> <select name="zip_code" onchange="makeRequest('getCity.php?state='+this.form.zip_code.options.value)" multiple="multiple" size="20">
6
3335
by: Charleees | last post by:
Hi all, I have a DropDown and a TextBox just bekeow it... I have to get the selected value from dropdown and set it as textBox Text.. The thing is i have to do this Without PostBack..... Is there any java script to do this functionality...
7
33679
by: prash.marne | last post by:
Hello, I have a simple form <form method="POST"> <select name="activity"> <option value="0">None</option> <option value="M" onclick="popup_onclick()">Select Multiple</option> <option value="1">Kayaking</option>
2
2378
by: Sebastian Fey | last post by:
hi, how do you select an option using javascript? i tried to setAttribute("selected", "disabled") to disable last selected and setAttribute("selected", "selected") for the newly selected. doesnt work :)
0
8231
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
8672
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
8614
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
8330
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
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6107
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
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4075
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...
2
1474
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.