Alpha-5
05-31-2009, 08:39 PM
Okay, i have this code meant to generate a set form. Its a bit long, but, it does what i want for the person i need it too. Now, i've had a few javascript errors with IE already, and have fixed those with some simple fixes. however, this one i cannot even think about what to do about it. What happens is, each time it cycles through, its supposed to give everything a name, such as WQ1, WQ2, WQ3. However, if i finish the cycle in IE, it gives them all the same name, WQ3, WQ3, WQ3. Does anyone know what i can do to fix this, or, have an idea atleast as a way i could work around this? Here's the code thats giving me issues. do note that it WORKS IN FIRE FOX
var Qc = 0;
function generateQuestionForms(addHere){
var node = document.getElementById(addHere);
if(node.value == parseInt(node.value) && node.value >= 0){
if(Qc > node.value){
var hasmore = confirm('You have selected to remove a few questions from the ballot. As a result,\n you will lose your last '+(Qc-node.value)+' questions, are you sure you wish to continue?');
if(hasmore){
while(Qc != node.value){
var deleted = document.getElementById("masterForm").lastChild;
deleted.parentNode.removeChild(deleted);
Qc--;
}
}
}
else{
while(node.value != Qc){
var fieldset = document.createElement("fieldset");
fieldset.setAttribute("id","Q"+Qc);
var table1 = document.createElement("table");
if(navigator.appName == "Microsoft Internet Explorer")
var tbody1 = document.createElement("tbody");
table1.setAttribute('border',1);
var tr1 = document.createElement("tr");
var th1 = document.createElement("th");
var txt1 = document.createTextNode("*Question/Decision");
th1.appendChild(txt1);
var td1 = document.createElement("td");
var in1 = document.createElement("input");
in1.setAttribute("type","text");
in1.setAttribute("name","WQ"+Qc);
td1.appendChild(in1);
tr1.appendChild(th1);
tr1.appendChild(td1);
var tr2 = document.createElement("tr");
var th2 = document.createElement("th");
var txt2 = document.createTextNode("**Populate list with Students in Checked grades:");
th2.appendChild(txt2);
var td2 = document.createElement("td");
for(var x = 9; x<13; x++){
var chktext = document.createTextNode(x+"th");
var chkboxs = document.createElement("input");
chkboxs.setAttribute("type","checkbox");
chkboxs.setAttribute("name","UESBG"+Qc+"[]");
chkboxs.setAttribute("value",x);
td2.appendChild(chktext);
td2.appendChild(chkboxs);
}
tr2.appendChild(th2);
tr2.appendChild(td2);
var tr3 = document.createElement("tr");
var th3 = document.createElement("th");
var txt3 = document.createTextNode("***Populate from which Gender(s) only: ");
th3.appendChild(txt3);
var td3 = document.createElement("td");
for(var x = 0; x<3; x++){
if(navigator.appName != "Microsoft Internet Explorer"){
var rbtn = document.createElement("input");
rbtn.setAttribute("name","fpr"+Qc);
if(x==0)
rbtn.setAttribute("checked",true);
rbtn.setAttribute("type","radio");
rbtn.setAttribute("value",x);
var textrbtn;
if(x==0)
textrbtn = "Both";
else if(x == 1)
textrbtn = "Male";
else if(x == 2)
textrbtn = "Female";
var rtxt = document.createTextNode(textrbtn);
td3.appendChild(rtxt);
td3.appendChild(rbtn);
}
else{
var rsel = document.createElement("select");
for(var x = 0; x<3; x++){
var seltext;
if (x == 0)
seltext = "Both";
else if (x == 1)
seltext = "Males";
else if (x == 2)
seltext = "Females";
rsel[x] = new Option(seltext);
rsel[x].setAttribute("value",x);
}
td3.appendChild(rsel);
}
}
tr3.appendChild(th3);
tr3.appendChild(td3);
var tr4 = document.createElement("tr");
var td4 = document.createElement("td");
td4.setAttribute("colspan",2);
var table2 = document.createElement("table");
if(navigator.appName == "Microsoft Internet Explorer")
var tbody2 = document.createElement("tbody");
var ttr1 = document.createElement("tr");
var tth1 = document.createElement("th");
var ttxt1 = document.createTextNode("**Custom Choices:");
tth1.appendChild(ttxt1);
var ttd1 = document.createElement("td");
var tin1 = document.createElement("input");
tin1.setAttribute("type","text");
tin1.setAttribute("name","C"+Qc+"[]");
if(navigator.appName == "Microsoft Internet Explorer"){
tin1.setAttribute('onfocus',function(){appendQ(this);});
tin1.setAttribute('onblur',function(){deleteQ(this);});
}
else{
tin1.setAttribute('onblur',"deleteQ(this)");
tin1.setAttribute('onfocus',"appendQ(this)");
}
ttd1.appendChild(tin1);
ttr1.appendChild(tth1);
ttr1.appendChild(ttd1);
if(navigator.appName == "Microsoft Internet Explorer"){
tbody2.appendChild(ttr1);
table2.appendChild(tbody2);
}
else
table2.appendChild(ttr1);
td4.appendChild(table2);
tr4.appendChild(td4);
var tr5 = document.createElement("tr");
var th5 = document.createElement("th");
var txt5 = document.createTextNode("*Gender Restrictions: ");
th5.appendChild(txt5);
var td5 = document.createElement("td");
var sel1 = document.createElement("select");
for(var x = 0; x<3; x++){
var seltext;
if (x == 0)
seltext = "None";
else if (x == 1)
seltext = "Males Only";
else if (x == 2)
seltext = "Females Only";
sel1[x] = new Option(seltext);
sel1[x].setAttribute("value",x);
}
sel1.setAttribute("name","GR"+Qc);
td5.appendChild(sel1);
tr5.appendChild(th5);
tr5.appendChild(td5);
var tr6 = document.createElement("tr");
var th6 = document.createElement("th");
var txt6 = document.createTextNode("Selection Type: ");
th6.appendChild(txt6);
var td6 = document.createElement("td");
var dspm = document.createElement("select");
for(var x = 1; x<5; x++){
/*********************************************/
///////////////////////////////////////////////
/*-------------------------------------------*/
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
//change this to go with Ethan's code. if he has it right that is.
if (x==1)
disptext="Select Box";
else if (x==2)
disptext="List Box";
else if (x==3)
disptext="Radio Buttons";
else if (x==4)
disptext="Check Boxes";
dspm[x-1] = new Option(disptext);
dspm[x-1].setAttribute("value",x);
}
dspm.setAttribute('id',"Dt"+Qc);
dspm.setAttribute('name',"Dt"+Qc);
if(navigator.appName == "Microsoft Internet Explorer"){
var ExEcUtOr = "RPS"+Qc
dspm.setAttribute('onchange',function(){enabledisable(ExEcUtOr,this);});
}
else
dspm.setAttribute('onchange',"enabledisable('Rps"+Qc+"',this)");
td6.appendChild(dspm);
tr6.appendChild(th6);
tr6.appendChild(td6);
var tr7 = document.createElement("tr");
var th7 = document.createElement("th");
var txt7 = document.createTextNode("****How Many people can be selected:");
th7.appendChild(txt7);
var td7 = document.createElement("td");
var sel2 = document.createElement("select");
sel2.setAttribute('name','Rps'+Qc);
sel2.setAttribute('id','Rps'+Qc);
for(var x = 1; x<101; x++){
sel2[x-1] = new Option(x);
sel2[x-1].setAttribute("value",x);
}
sel2.setAttribute('disabled',true);
td7.appendChild(sel2);
tr7.appendChild(th7);
tr7.appendChild(td7);
if(navigator.appName != "Microsoft Internet Explorer"){
table1.appendChild(tr1);
table1.appendChild(tr2);
table1.appendChild(tr3);
table1.appendChild(tr4);
table1.appendChild(tr5);
table1.appendChild(tr6);
table1.appendChild(tr7);
}
else{
tbody1.appendChild(tr1);
tbody1.appendChild(tr2);
tbody1.appendChild(tr3);
tbody1.appendChild(tr4);
tbody1.appendChild(tr5);
tbody1.appendChild(tr6);
tbody1.appendChild(tr7);
table1.appendChild(tbody1);
}
fieldset.appendChild(table1);
Qc++;
document.getElementById("masterForm").appendChild(fieldset);
}
Qc=node.value;
}
}
}
that is the code that is the creation form. The other scripts on the page are as follows:
function appendQ(node1)
{
if(node1.value==""){
var nameData = node1.name;
var Qtba = nameData.substring(1,3);
if(Qtba != parseInt(Qtba))
Qtba = Qtba.substring(0,1);
var node = node1.parentNode.parentNode.parentNode;
var node2 = document.createElement("tr");
var node3 = document.createElement("td");
var node4 = document.createElement("td");
node4.appendChild(document.createTextNode("**Custom Choices: "));
node2.setAttribute("id","Second Parent");
node2.appendChild(node4);
var input = document.createElement("input");
input.setAttribute('type',"text");
input.setAttribute('name',"C"+Qtba+"[]");
if(navigator.appName == "Microsoft Internet Explorer"){
input.setAttribute('onfocus',function(){appendQ(this);});
input.setAttribute('onblur',function(){deleteQ(this);});
}
else{
input.setAttribute('onblur',"deleteQ(this)");
input.setAttribute('onfocus',"appendQ(this)");
}
node3.appendChild(input);
node2.appendChild(node3);
node.appendChild(node2);
}
}
function deleteQ(node1){
if(node1.value==""){
var node = node1.parentNode.parentNode.parentNode;
node.removeChild(node1.parentNode.parentNode);
}
}
function submit(){
if(Qc>0)
{
var cont = true;
var thing = document.getElementById("Nq");
if(thing.value == "")
cont = false;
for(var x = 0; x<Qc&&cont; x++){
var alpha = document.getElementsByName("WQ"+x)[0];
if(alpha.value == "")
cont=false;
var beta = new Array();
var gamma = 4;
var beta = document.getElementsByName("UESBG"+x+"[]");
for(var delta = 0; delta<4; delta++){
if(beta[delta].checked == false)
gamma--;
}
if(gamma == 0){
var iota = document.getElementsByName("C"+x+"[]");
alert(iota[0].value);
if(iota[0].value == "")
cont=false;
}
}
if(cont)
document.master.submit();
else
alert("There are some null fields. Please fill these in.");
}
else
alert("You have not added any questions, please go back and try again");
}
function enabledisable(id,ctrl){
var node = document.getElementById(id);
if(ctrl.value == 4){
node.removeAttribute('disabled');
}
else{
if(!node.disabled)
node.setAttribute('disabled',true);
}
}
Alpha
var Qc = 0;
function generateQuestionForms(addHere){
var node = document.getElementById(addHere);
if(node.value == parseInt(node.value) && node.value >= 0){
if(Qc > node.value){
var hasmore = confirm('You have selected to remove a few questions from the ballot. As a result,\n you will lose your last '+(Qc-node.value)+' questions, are you sure you wish to continue?');
if(hasmore){
while(Qc != node.value){
var deleted = document.getElementById("masterForm").lastChild;
deleted.parentNode.removeChild(deleted);
Qc--;
}
}
}
else{
while(node.value != Qc){
var fieldset = document.createElement("fieldset");
fieldset.setAttribute("id","Q"+Qc);
var table1 = document.createElement("table");
if(navigator.appName == "Microsoft Internet Explorer")
var tbody1 = document.createElement("tbody");
table1.setAttribute('border',1);
var tr1 = document.createElement("tr");
var th1 = document.createElement("th");
var txt1 = document.createTextNode("*Question/Decision");
th1.appendChild(txt1);
var td1 = document.createElement("td");
var in1 = document.createElement("input");
in1.setAttribute("type","text");
in1.setAttribute("name","WQ"+Qc);
td1.appendChild(in1);
tr1.appendChild(th1);
tr1.appendChild(td1);
var tr2 = document.createElement("tr");
var th2 = document.createElement("th");
var txt2 = document.createTextNode("**Populate list with Students in Checked grades:");
th2.appendChild(txt2);
var td2 = document.createElement("td");
for(var x = 9; x<13; x++){
var chktext = document.createTextNode(x+"th");
var chkboxs = document.createElement("input");
chkboxs.setAttribute("type","checkbox");
chkboxs.setAttribute("name","UESBG"+Qc+"[]");
chkboxs.setAttribute("value",x);
td2.appendChild(chktext);
td2.appendChild(chkboxs);
}
tr2.appendChild(th2);
tr2.appendChild(td2);
var tr3 = document.createElement("tr");
var th3 = document.createElement("th");
var txt3 = document.createTextNode("***Populate from which Gender(s) only: ");
th3.appendChild(txt3);
var td3 = document.createElement("td");
for(var x = 0; x<3; x++){
if(navigator.appName != "Microsoft Internet Explorer"){
var rbtn = document.createElement("input");
rbtn.setAttribute("name","fpr"+Qc);
if(x==0)
rbtn.setAttribute("checked",true);
rbtn.setAttribute("type","radio");
rbtn.setAttribute("value",x);
var textrbtn;
if(x==0)
textrbtn = "Both";
else if(x == 1)
textrbtn = "Male";
else if(x == 2)
textrbtn = "Female";
var rtxt = document.createTextNode(textrbtn);
td3.appendChild(rtxt);
td3.appendChild(rbtn);
}
else{
var rsel = document.createElement("select");
for(var x = 0; x<3; x++){
var seltext;
if (x == 0)
seltext = "Both";
else if (x == 1)
seltext = "Males";
else if (x == 2)
seltext = "Females";
rsel[x] = new Option(seltext);
rsel[x].setAttribute("value",x);
}
td3.appendChild(rsel);
}
}
tr3.appendChild(th3);
tr3.appendChild(td3);
var tr4 = document.createElement("tr");
var td4 = document.createElement("td");
td4.setAttribute("colspan",2);
var table2 = document.createElement("table");
if(navigator.appName == "Microsoft Internet Explorer")
var tbody2 = document.createElement("tbody");
var ttr1 = document.createElement("tr");
var tth1 = document.createElement("th");
var ttxt1 = document.createTextNode("**Custom Choices:");
tth1.appendChild(ttxt1);
var ttd1 = document.createElement("td");
var tin1 = document.createElement("input");
tin1.setAttribute("type","text");
tin1.setAttribute("name","C"+Qc+"[]");
if(navigator.appName == "Microsoft Internet Explorer"){
tin1.setAttribute('onfocus',function(){appendQ(this);});
tin1.setAttribute('onblur',function(){deleteQ(this);});
}
else{
tin1.setAttribute('onblur',"deleteQ(this)");
tin1.setAttribute('onfocus',"appendQ(this)");
}
ttd1.appendChild(tin1);
ttr1.appendChild(tth1);
ttr1.appendChild(ttd1);
if(navigator.appName == "Microsoft Internet Explorer"){
tbody2.appendChild(ttr1);
table2.appendChild(tbody2);
}
else
table2.appendChild(ttr1);
td4.appendChild(table2);
tr4.appendChild(td4);
var tr5 = document.createElement("tr");
var th5 = document.createElement("th");
var txt5 = document.createTextNode("*Gender Restrictions: ");
th5.appendChild(txt5);
var td5 = document.createElement("td");
var sel1 = document.createElement("select");
for(var x = 0; x<3; x++){
var seltext;
if (x == 0)
seltext = "None";
else if (x == 1)
seltext = "Males Only";
else if (x == 2)
seltext = "Females Only";
sel1[x] = new Option(seltext);
sel1[x].setAttribute("value",x);
}
sel1.setAttribute("name","GR"+Qc);
td5.appendChild(sel1);
tr5.appendChild(th5);
tr5.appendChild(td5);
var tr6 = document.createElement("tr");
var th6 = document.createElement("th");
var txt6 = document.createTextNode("Selection Type: ");
th6.appendChild(txt6);
var td6 = document.createElement("td");
var dspm = document.createElement("select");
for(var x = 1; x<5; x++){
/*********************************************/
///////////////////////////////////////////////
/*-------------------------------------------*/
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
//change this to go with Ethan's code. if he has it right that is.
if (x==1)
disptext="Select Box";
else if (x==2)
disptext="List Box";
else if (x==3)
disptext="Radio Buttons";
else if (x==4)
disptext="Check Boxes";
dspm[x-1] = new Option(disptext);
dspm[x-1].setAttribute("value",x);
}
dspm.setAttribute('id',"Dt"+Qc);
dspm.setAttribute('name',"Dt"+Qc);
if(navigator.appName == "Microsoft Internet Explorer"){
var ExEcUtOr = "RPS"+Qc
dspm.setAttribute('onchange',function(){enabledisable(ExEcUtOr,this);});
}
else
dspm.setAttribute('onchange',"enabledisable('Rps"+Qc+"',this)");
td6.appendChild(dspm);
tr6.appendChild(th6);
tr6.appendChild(td6);
var tr7 = document.createElement("tr");
var th7 = document.createElement("th");
var txt7 = document.createTextNode("****How Many people can be selected:");
th7.appendChild(txt7);
var td7 = document.createElement("td");
var sel2 = document.createElement("select");
sel2.setAttribute('name','Rps'+Qc);
sel2.setAttribute('id','Rps'+Qc);
for(var x = 1; x<101; x++){
sel2[x-1] = new Option(x);
sel2[x-1].setAttribute("value",x);
}
sel2.setAttribute('disabled',true);
td7.appendChild(sel2);
tr7.appendChild(th7);
tr7.appendChild(td7);
if(navigator.appName != "Microsoft Internet Explorer"){
table1.appendChild(tr1);
table1.appendChild(tr2);
table1.appendChild(tr3);
table1.appendChild(tr4);
table1.appendChild(tr5);
table1.appendChild(tr6);
table1.appendChild(tr7);
}
else{
tbody1.appendChild(tr1);
tbody1.appendChild(tr2);
tbody1.appendChild(tr3);
tbody1.appendChild(tr4);
tbody1.appendChild(tr5);
tbody1.appendChild(tr6);
tbody1.appendChild(tr7);
table1.appendChild(tbody1);
}
fieldset.appendChild(table1);
Qc++;
document.getElementById("masterForm").appendChild(fieldset);
}
Qc=node.value;
}
}
}
that is the code that is the creation form. The other scripts on the page are as follows:
function appendQ(node1)
{
if(node1.value==""){
var nameData = node1.name;
var Qtba = nameData.substring(1,3);
if(Qtba != parseInt(Qtba))
Qtba = Qtba.substring(0,1);
var node = node1.parentNode.parentNode.parentNode;
var node2 = document.createElement("tr");
var node3 = document.createElement("td");
var node4 = document.createElement("td");
node4.appendChild(document.createTextNode("**Custom Choices: "));
node2.setAttribute("id","Second Parent");
node2.appendChild(node4);
var input = document.createElement("input");
input.setAttribute('type',"text");
input.setAttribute('name',"C"+Qtba+"[]");
if(navigator.appName == "Microsoft Internet Explorer"){
input.setAttribute('onfocus',function(){appendQ(this);});
input.setAttribute('onblur',function(){deleteQ(this);});
}
else{
input.setAttribute('onblur',"deleteQ(this)");
input.setAttribute('onfocus',"appendQ(this)");
}
node3.appendChild(input);
node2.appendChild(node3);
node.appendChild(node2);
}
}
function deleteQ(node1){
if(node1.value==""){
var node = node1.parentNode.parentNode.parentNode;
node.removeChild(node1.parentNode.parentNode);
}
}
function submit(){
if(Qc>0)
{
var cont = true;
var thing = document.getElementById("Nq");
if(thing.value == "")
cont = false;
for(var x = 0; x<Qc&&cont; x++){
var alpha = document.getElementsByName("WQ"+x)[0];
if(alpha.value == "")
cont=false;
var beta = new Array();
var gamma = 4;
var beta = document.getElementsByName("UESBG"+x+"[]");
for(var delta = 0; delta<4; delta++){
if(beta[delta].checked == false)
gamma--;
}
if(gamma == 0){
var iota = document.getElementsByName("C"+x+"[]");
alert(iota[0].value);
if(iota[0].value == "")
cont=false;
}
}
if(cont)
document.master.submit();
else
alert("There are some null fields. Please fill these in.");
}
else
alert("You have not added any questions, please go back and try again");
}
function enabledisable(id,ctrl){
var node = document.getElementById(id);
if(ctrl.value == 4){
node.removeAttribute('disabled');
}
else{
if(!node.disabled)
node.setAttribute('disabled',true);
}
}
Alpha