Forum Moderators: open
document.getElementById("showLabels").innerHTML = "<table><tr> <td width='120'>Field Name</td><td width='10'> </td><td width='70'>Required?</td><td width='10'> </td><td width='120'>Value</td><td width='10'> </td><td width='134'>Length</td><td width='10'> </td><td width='100'><div id='howlong1'></div></td></tr>";
document.getElementById(showQuantity).innerHTML = "<tr><td><input type='text' name='fieldtextname" + j + "' value='' size='20'></td><td width='10'> </td><td width='70'><select name='requiredtext" + j + "'><option selected>Select</option><option value='Yes'>Yes</option><option value='No'>No</option></select></td><td width='10'> </td><td><input type='text' name='valuetext" + j + "' value='' size='20'></td><td width='10'> </td><td width='134'> <label> Empty <input type='radio' name='RadiotextGroup" + j + "' value='empty' onClick='hidelength(" + j + ")'>Length</label> <label><input type='radio' name='RadiotextGroup" + j + "' value='length' onClick='showlength(" + j + ")'></label></td><td width='10'> </td><td width='100'><div id ='lengthbox1'></div></td></tr></table>";
document.getElementById("textfieldbuildbutton").innerHTML = "<input type='button' name='build' value='Build code' onClick='javascript:textfieldbuildCode(formTool.fieldtextname1.value,formTool.fieldtextname3.value);'>";
}
}
}
}
I have the div tags later on down which the innerHTML goes into. I was wondering if there was a way to do like a foreach loop so the loop can just go through and gather all of the user input and put it into an array. If anyone can help I would greatly appreciate it sooo much. Thank you in advance!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#main{height:4000px;}
</style>
<script type="text/javascript">
function fillPg(){
var pg_ht=document.getElementById("main").offsetHeight;
var cont_ht=new Array(200,300,200,300);
var cont_str=new Array("alpha","beta","delta","gamma");
var ttl_ht=0;
var wrt_str="";
var arr_ln=cont_str.length;
while(ttl_ht<pg_ht){
for(var i=0;i<arr_ln;i++){
wrt_str+="<div>"+cont_str[i]+"</div>";
ttl_ht+=cont_ht[i];
}
}
document.getElementById("main").innerHTML=wrt_str;
}
</script>
</head>
<body onload="fillPg();">
<div id="main">
</div>
</body>
</html>
document.getElementById("textfieldbuildbutton").innerHTML = "<input type='button' name='build' value='Build code' onClick='javascript:textfieldbuildCode(formTool.fieldtextname1.value,formTool.fieldtextname3.value);'>";
The onClick command needs to pass it all of the parameters, I'm not sure how to do this since the amount of fields can vary....also I'm not sure how to get the variables once they have been passed. All help would be greatly appreciated and I thank you in advance.
var cont_str = "<tr><td><input type='text' name='fieldtextname" + j + "' value='' size='20'></td><td width='10'> </td><td width='70'><select name='requiredtext" + j + "'><option value='Yes'>Yes</option><option value='No'>No</option></select></td><td width='10'> </td><td><input type='text' name='valuetext" + j + "' value='' size='20'></td><td width='10'> </td><td width='134'> <label> Empty <input type='radio' name='RadiotextGroup" + j + "' value='empty'>Length</label> <label><input type='radio' name='RadiotextGroup" + j + "' value='length'></label></td><td width='10'> </td><td><input type='text' name='length" + j + "' value='0' size='20' onClick='checklength()' disabled></td></tr></table>";
wrt_str+="<div>"+cont_str[j]+"</div>";
From #3
document.getElementById("textfieldbuildbutton").innerHTML = ...
What type of element is the element id:textfieldbuildbutton?
Note that you don't need the javascript: protocol in an onclick event handler.
From #4
giving me an error saying that wr_str is null
That's because you are attempting to add (+=) to a variable that you haven't yet defined.
Defining: wrt_str = "" should solve that.
Overall, it might be better to do all this using DOM techniques, createElement etc, instead of building complicated strings, and having to mess with quoting. Using strings all the time makes it very difficult to create relationships between objects.
var cont_str = new Array("<tr><td><input type='text' name='fieldtextname" + j + "' value='' size='20'></td><td width='10'> </td><td width='70'><select name='requiredtext" + j + "'><option value='Yes'>Yes</option><option value='No'>No</option></select></td><td width='10'> </td><td><input type='text' name='valuetext" + j + "' value='' size='20'></td><td width='10'> </td><td width='134'> <label> Empty <input type='radio' name='RadiotextGroup" + j + "' value='empty'>Length</label> <label><input type='radio' name='RadiotextGroup" + j + "' value='length'></label></td><td width='10'> </td><td><input type='text' name='length" + j + "' value='0' size='20' onClick='checklength()' disabled></td></tr></table>");
wrt_str+="<div>"+cont_str[j]+"</div>";
This code doesnt' give me any errors but it says that wrt_str is undefined when it prints it out to the page. I think its something with how I'm putting in the information into the cont_str array but I'm not sure how to really do that...I appreciate all of your help still...