Saturday, 24 August 2013

Javascript: function associated with create element not working

Javascript: function associated with create element not working

I have a select element from createElement which I want to have replaced
with a text input element with an onchange event, but my code for it
doesn't work. Here's the code (the select element itself is appended to
other div elements that are also created):
<script>
var countess = 0;
function adadd(){
var child = document.getElementById("geneadd");
if (child.value === "add")
{countess++;
if (countess < 2)
{
var divi=document.createElement("div");
divi.name = "diviena";
divi.id = "divienid";
divi.class = "table";
var elemdivi = document.getElementById("fieldsetid");
elemdivi.appendChild(divi);
}
var divii=document.createElement("div");
divii.name = "divienaa" + countess;
divii.id = "divienidd" + countess;
var elemdivii = document.getElementById("divienid");
elemdivii.appendChild(divii);
var sell=document.createElement("select");
sell.id = "den3erw" + countess;
sell.name = "oute3erw" + countess;
sell.onchange = "lechangefinal()";
var har = document.getElementById(divii.id);
har.appendChild(sell);
var opt=document.createElement("option");
opt.id = "disept" + countess/*<?php echo $varia; ?>*/;
opt.value = "";
var nar = document.getElementById(sell.id);
sell.appendChild(opt);
document.getElementById(opt.id).innerHTML="Select Gene...";
...more options in between...
var opta=document.createElement("option");
opta.id = "other" + countess/*<?php echo $varia; ?>*/;
opta.value = "other";
var nari = document.getElementById(sell.id);
sell.appendChild(opta);
document.getElementById(opta.id).innerHTML="other...";
}}
And this is the function that I want to be working on the create element:
function lechangefinal(){
for (var iii = 0; iii <= 100; iii++){
var childi = document.getElementById("den3erw" + iii);
if (childi.value === "other")
{parent.removeChild(childi);
var inpuat=document.createElement("input");
inpuat.type = "text";
inpuat.name = "2";
var elemi=document.getElementById("divienidd" + iii);
elemi.appendChild(inpuat);}}}

No comments:

Post a Comment