473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

IE6 failing to set checkbox or radio buttons

Hi,
I've got javascript code which uses a basic logical statement to determine whether a checkbox or radio button should be set to checked:

radio.checked = (map.getLayer(divId) == map.baseLayer);

Firefox has no trouble with this, but IE6 doesn't check anything!

Any idea why this might be?

Cheers,
Jon
Feb 15 '08 #1
6 4013
gits
5,390 Expert Mod 4TB
please show more of your code ... what does getLayer do? and what is baseLayer? and what is map?

kind regards
Feb 15 '08 #2
The code is using OpenLayers javascript client for displaying maps.

Basically map.getLayer(divId) just returns a map layer using the given ID and map.baseLayer is the current visible layer. I'm just checking to see if they are equal.

The logical statement definitely works (even in IE) because when I output it in an alert is displays the correct value of true or false.

Jon
Feb 15 '08 #3
Sorry to post again, just though I should post the whole code section. Basically it's a for-loops for contructing a list of map layers:

Expand|Select|Wrap|Line Numbers
  1. for (var i=0; i<baseLayers.length; i++)
  2. {
  3.     var divId = baseLayers[i].id;
  4.     //individual baselayer
  5.     var baseLayerElem = document.createElement("li");
  6.         var radio = document.createElement('input');
  7.             radio.type = 'radio';
  8.             radio.name = 'base';
  9.             radio.value = divId;
  10.             radio.id = divId + "Rad";
  11.             radio.onclick = Function("ChangesClient.layerOptionsPanel.toggleBase('"+divId+"')");
  12.             radio.checked = (map.getLayer(divId) == map.baseLayer);
  13.         var a = document.createElement('a');
  14.             a.className = 'ccLink';
  15.             a.href = "javascript:ChangesClient.Util.toggleDiv('" + divId + "')";
  16.             a.innerHTML = baseLayers[i].name;
  17.         var optionsDiv = document.createElement('div');
  18.             optionsDiv.className = 'ccLayerOptionsBaseLayerOptions';
  19.             optionsDiv.id = divId;
  20.             optionsDiv.innerHTML = "Baselayer options for" + divId;
  21.             optionsDiv.style.display = 'none';
  22.         baseLayerElem.appendChild(radio);
  23.         baseLayerElem.appendChild(a);
  24.         baseLayerElem.appendChild(optionsDiv);
  25.     baseLayerList.appendChild(baseLayerElem);
  26.     this.layerList.push(divId);
  27. }
Feb 15 '08 #4
acoder
16,027 Expert Mod 8TB
IE has a problem with dynamically appended checkboxes/radio buttons. It doesn't respect the checked property. There are two solutions, either use defaultChecked or check it after appending. I've mentioned some of these bugs/quirks in a howto/article.
Feb 15 '08 #5
Thank you very much, I've just added the element ID's to a list and looped through it at the end calling

document.getElementById(ID).checked = true;

The most I mess around with JS, the more I think that IE is a pain in the arse.

Cheers,
Jon
Feb 15 '08 #6
acoder
16,027 Expert Mod 8TB
A pain indeed. Glad it helped.
Feb 15 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: PhiSYS | last post by:
I want to know what's wrong with this code (I'm an amateur programmer). I'm trying to check if every field has a value or if checkboxes/radios have at least one item checked on each group (yes, you...
1
by: David Wake | last post by:
I have two radio buttons and two checkboxes in a form. I'm trying to write some code so that when a radio button is selected, its corresponding checkbox is disabled. My code looks like this: ...
1
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?...
4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
0
by: sam | last post by:
I have 2 radio buttons on my form which are hidden. I need to have these radio buttons visible once a checkbox is selected. The radio buttons are hidden on loading of the form but I cannot make them...
5
by: tshad | last post by:
Is there a way to allow a user to press a radio button if it is already selected? There is an onCheckedChanged event that fires when the person presses the button and it is isn't selected...
3
by: newjazzharmony | last post by:
Hello group, I want to automatically select a specific checkbox when a user clicks (selects) a specific item in a radiobutton group. Both controls are in the same form. Let's say for...
10
by: Bishman | last post by:
Hi, I need to programmatically allow or disallow the selection of multiple checkboxes on a form . At certain times I only want to allow a single selection, at other times I may wish to allow...
2
by: runway27 | last post by:
i am using a self submitting form <form action="<?php echo $_SERVER; ?>" method="POST" id="test2" name="test1"> i need to do a validation of textfields, checkboxes, radio buttons i am able...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.