Still having problem with dynamic creating of radiobuttons

wxdqz

New Member
Hi,
I use the methods:
-createElement
-setAttribute
to add records in a table.

This is the piece of code:
=========================
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

function Update_Info() {
var i;
var Cadena;
renglon = -999999;
for (i=0;i< document.getElementById('TABLA_ESTUDIOS').rows.length;i++)
{
if (document.getElementById('celda'+i+'7').checked)
{
renglon = i;
Cadena = document.getElementById('celda'+i+'7').Sarta;
}
}
alert('You chose to update the record # ' + renglon + '. Value= 'http://www.webdeveloper.com/forum/archive/index.php/+ Cadena);
}



function Add_Record(form){

var myIndex;
var grp = document.academicos.raRegistro2;

if (document.getElementById('Tabla_Estudios').rows.length == 0)
{
myIndex = 0;
}

var miRadioBtn = "<INPUT TYPE=RADIO NAME = raRegistro2 Sarta='VALUE_1|VALUE_2|VALUE_3|VALUE_4|VALUE_5|VALUE_6'>";
var tbody = document.getElementById('Tabla_Estudios').getElementsByTagName("TBODY")[0];
var row = document.createElement("TR");

var td1 = document.createElement("TD");
td1.setAttribute("id","celda"+myIndex+"7");
td1.appendChild (document.createElement(miRadioBtn));

row.appendChild(td1);
tbody.appendChild(row);

}


function erase_Record() {
var i;
var Cadena;
renglon = 0;
if (document.getElementById('Tabla_Estudios').rows.length > 1)
{
renglon=-999999;
for (i=0; i < document.academicos.raRegistro2.length; i++)
{
if (document.academicos.raRegistro2.checked)
{
renglon = i;
}
}

if (renglon == -999999)
{
alert('You must select the record to erase!');
}
else
{
renglon++;
document.getElementById('Tabla_Estudios').deleteRow(renglon);
}
}
}

</SCRIPT>
</HEAD>


<FORM NAME="academicos" ACTION = "./nom_mostrar_info.php?IndTabla=3" METHOD="POST">
<TABLE ID='TABLA_ESTUDIOS' BORDER='1'>
<TBODY>
<TR>
<TD> Tabla </TD>
</TR>
</TBODY>
</TABLE>
<A HREF='http://www.webdeveloper.com/forum/archive/index.php/#' onClick='javascript:Add_Record()'>Add a new radiobuttion</A>
<BR>
<A HREF='http://www.webdeveloper.com/forum/archive/index.php/#' onClick='javascript:erase_Record()'>Delete radiobutton</A>
<BR>
</FORM>
</HTML>
=========================

Do the following in order to replicate the issue:

1) Add a new radiobutton, clicking the link "Add record",
2) Once you add the new radiobutton, try to delete it, clicking in the link "Delete record".

It seems the FIRST time it creates the radiobutton, the value of the property "document.academicos.raRegistro2.length" is not set.

But, If you insert more and more radiobuttons, the "document.academicos.raRegistro2.length" is set successfully.

What am I doing wrong?

I appreciate your kind help.

t.i.a.

Caliban
 
Back
Top