473,856 Members | 1,850 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 2513
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
2567
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
6321
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
3803
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
1952
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
3683
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
3671
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
3355
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
33699
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
2389
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
9767
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11081
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...
1
10806
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,...
1
7939
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
5773
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
5967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4189
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3214
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.