Dynamic radio buttons and IE6

jagard

New Member
I am trying to create a form page which can contain input from dynamically created radio buttons

below is an example which works correctly in Mozilla/Netscape but fails in IE6

does anybody have any ideas

thanks
/*****************************************/
<html>
<head>
<script language="Javascript">
<!--
var filterel = 0;
function fnAddSel()
{

filterel++;
var availfilters = document.getElementById("availfilters");
var oTB = document.getElementById("mytbody");
var oNewTR = document.createElement("TR");
var oNewTD1 = document.createElement("TD");
var oNewLable = document.createTextNode(availfilters.value);
oNewTD1.appendChild(oNewLable);
oNewTR.appendChild(oNewTD1);
var oNewTD2 = document.createElement("TD");
oNewTR.appendChild(oNewTD2);
switch ( availfilters.value ) {
case "water" :
var oNewradio1 = document.createElement("input");

oNewradio1.name = "water" + filterel;
oNewradio1.type = "checkbox";
oNewradio1.value = "yes";
oNewradio1.defaultChecked = true;

var oNewradio2 = document.createElement("input");

oNewradio2.name = "water" + filterel;
oNewradio2.type = "checkbox";
oNewradio2.value = "no";

oNewTD2.appendChild(oNewradio1);
oNewTD2.appendChild(oNewradio2);
break;
case "logical" :
var oNewradio1 = document.createElement("input");

oNewradio1.name = "log" + filterel;
oNewradio1.type = "radio";
oNewradio1.value = "on";
oNewradio1.defaultChecked = true;


var oNewradio2 = document.createElement("input");

oNewradio2.name = "log" + filterel;
oNewradio2.type = "radio";
oNewradio2.value = "off";
oNewradio2.defaultChecked = false;
oNewTD2.appendChild(oNewradio1);
oNewTD2.appendChild(oNewradio2);
break;
default :
var oNewInput = document.createElement("Input");
oNewInput.name = "filter" + filterel;
oNewInput.value = "NEW";
oNewTD2.appendChild(oNewInput);
}
oTB.appendChild(oNewTR);
}

function SubmitForm()
{
document.myform.submit();
}
// -->
</script>
</head>
<body>
<select id=availfilters>
<option selected value="vg-lup"> Land Use
<option value="sale"> Sale
<option value="water"> Water
<option value="logical"> log
</select>
<input TYPE="button" VALUE="Add Filter" onclick="fnAddSel()" >

<form name="myform" METHOD="get" ACTION="">
<table>
<thead>
<tr><th colspan=2>Filter by</th></tr>
</thead>
<tbody id="mytbody">
</tbody>
</table>
</form>
<button onclick="javascript:document.myform.submit()"> Submit </button>
<br>
<br>

</body>
</html>
/*********************************************/
 

jamesmc

Member
Hi Jagard,

The problem is that there is no NAME= in the radio element therefore the page can not pair the two radio buttons together! I have got your code working in IE6 by changing the part of the case statement that handles the logical output to:

Code:
	case "logical" : 
	  var oNewradio1 = document.createElement("<INPUT type=radio name=log" + filterel + " checked value=on>");
	  var oNewradio2 = document.createElement("<INPUT type=radio name=log" + filterel + " value=off>");
	  oNewTD2.appendChild(oNewradio1);
	  oNewTD2.appendChild(oNewradio2);
	  break;

As you can see, I have changes the CreateElement method slightly. You will notice that your method of creating the elements on the screen doesnt actually insert NAME for any of them so you may have trouble reading the values when you process the form. Out of curiousity, how do you read the values when you submit the form?

HTH,

James.
 

jagard

New Member
Thanks

to read the values from the submited for i use
get-value(?) which returns a comma separated list of all the fields on the sumited form
i then use a simple loop to step through the list and retrieve the data
do i = 1 to num-entries(get-field(?)):
x = get-field(entry(i, get-field(?)).
end.


again thanks very much :)

jamesmc said:
Hi Jagard,

The problem is that there is no NAME= in the radio element therefore the page can not pair the two radio buttons together! I have got your code working in IE6 by changing the part of the case statement that handles the logical output to:

Code:
 	case "logical" : 
 	 var oNewradio1 = document.createElement("<INPUT type=radio name=log" + filterel + " checked value=on>");
 	 var oNewradio2 = document.createElement("<INPUT type=radio name=log" + filterel + " value=off>");
 	  oNewTD2.appendChild(oNewradio1);
 	  oNewTD2.appendChild(oNewradio2);
 	  break;

As you can see, I have changes the CreateElement method slightly. You will notice that your method of creating the elements on the screen doesnt actually insert NAME for any of them so you may have trouble reading the values when you process the form. Out of curiousity, how do you read the values when you submit the form?

HTH,

James.
 
Top