I am creating a form with which a user can make forms. After filling in basic details like Title, Author, Description, the user can add multiple input fields of different types.
This is done in the form of a table, with each row acting for a single input, i.e. input1, input2, input3, etc. The user selects the input type (text, textarea, dropdown, radio, checkboxes) from a dropdown box, which dynamically changes the contents of the adjacent cell to give them the appropriate fields for that input.
For example, I want my first input to be 'text', so I select that. I can then give a title, description and length for the text box. I want my second input to be a dropdown box, so I select that. Now I can add the title and description, but I have a spinner to select the number of choices in the dropdown box, and a series of text boxes to type my choices in (which of course changes according to the spinner).
Eventually all the form details get passed to an ASP script which generates an XML file containing all the relevant information. Then a different ASP script can come along and parse that XML and create the form I wanted to make, nicely integrated with the rest of my website.
All of that stuff works just fine. I'm a javascript novice, but I have managed to make some progress and I feel reasonably comfortable using the DOM to add elements and things.
My problem is this: Internet Explorer (I'm testing in IE6 and IE7) doesn't like it when I try to work with radio buttons. I'm making the settings for a radio button input, and I would like the user to be able to select a preset option. I have the structure working pretty well - the user ticks a box if they want a preset option, and magically some radio buttons appear next to their list of options.
The idea is that they can select one of the radio buttons to choose that option as their preset one.
Sub-problem 1: IE does not display the radio buttons correctly. As far as I can tell, they still function, but if you click on one of the dynamically-created radio buttons, it doesn't 'fill in' like a normal one does. Firefox displays them fine.I know I have to iterate over the list of radio buttons and use "if x.checked" on each to see if that one's checked. The way I understand it is that you grab all the elements with a given name (i.e. the radio buttons) and use them like an array. Again, this works just fine in Firefox.
Sub-problem 2: To get around that, I wanted to give a light shading to the input box which has been pre-selected as a visual cue. Sounds simple enough, right? Well IE again doesn't want to work.
IE throws up an error, saying "'undefined' is null or not an object".
Even a little test to get the length of the array (document.formCreator.input1_chk.length) says "'.length' is null or not an object". That's obviously wrong. Using the same code, Firefox gives the number of options with no problem.
I either need the first problem or the second problem fixed, since they're both supposed to be doing roughly the same thing (that is, giving the user a visual reference for their pre-selected option).
Here's the code for the colour changing:
Expand|Select|Wrap|Line Numbers
- function selectRadio(id) {
- var inputTbody = document.getElementById(id.replace("_chk","_tbod"));
- var newID = id.replace("_chk","");
- var count = document.getElementById(id.replace("_chk","_count")).value;
- var radioObj = document.formCreator.input1_chk;
- for (i=0;i<=(count-1);i++) {
- if (radioObj[i].checked) {
- document.getElementById(newID+"_optrow"+(i+1)).style.backgroundColor = "#cccccc";
- } else {
- document.getElementById(newID+"_optrow"+(i+1)).style.backgroundColor = "#ffffff";
- }
- }
- }
Any ideas at all would be welcome, I've been working on this for a while now.