This is going to be a long one, but hopefully that will make it easier to understand. I know I don't like posts with too little detail when I'm searching for help.
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.
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.
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.formC reator.input1_c hk.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:
[CODE=javascript]function selectRadio(id) {
var inputTbody = document.getEle mentById(id.rep lace("_chk","_t bod"));
var newID = id.replace("_ch k","");
var count = document.getEle mentById(id.rep lace("_chk","_c ount")).value;
var radioObj = document.formCr eator.input1_ch k;
for (i=0;i<=(count-1);i++) {
if (radioObj[i].checked) {
document.getEle mentById(newID+ "_optrow"+(i+1) ).style.backgro undColor = "#cccccc";
} else {
document.getEle mentById(newID+ "_optrow"+(i+1) ).style.backgro undColor = "#ffffff";
}
}
}[/CODE]
'formCreator' is the name of the form, 'input1_chk' is the name of the radio buttons for all the options in input1, 'id' coming into the function is the name as well (this.name from the radio buttons), I was just forcing it to check input1 to debug.
Any ideas at all would be welcome, I've been working on this for a while now.
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.
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.
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.
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.
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.formC reator.input1_c hk.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:
[CODE=javascript]function selectRadio(id) {
var inputTbody = document.getEle mentById(id.rep lace("_chk","_t bod"));
var newID = id.replace("_ch k","");
var count = document.getEle mentById(id.rep lace("_chk","_c ount")).value;
var radioObj = document.formCr eator.input1_ch k;
for (i=0;i<=(count-1);i++) {
if (radioObj[i].checked) {
document.getEle mentById(newID+ "_optrow"+(i+1) ).style.backgro undColor = "#cccccc";
} else {
document.getEle mentById(newID+ "_optrow"+(i+1) ).style.backgro undColor = "#ffffff";
}
}
}[/CODE]
'formCreator' is the name of the form, 'input1_chk' is the name of the radio buttons for all the options in input1, 'id' coming into the function is the name as well (this.name from the radio buttons), I was just forcing it to check input1 to debug.
Any ideas at all would be welcome, I've been working on this for a while now.
Comment