I got this code below that dynamically adds a row if someone clicks on the “Add Child” hyperlink.
I have setup 2 field areas statically that that read the childs gender, age, etc.
When I read these is I use request(“child1_gender”) in ASP and it returns a value fine. But when I start trying to read these dynamic fields, I get nothing.
Here’s the JS code:
[code]
function addEvent()
{
var ni = document.getElementById(‘myDiv’);
var numi = document.getElementById(‘theValue’);
var num = (document.getElementById(“theValue”).value -1)+ 2;
numi.value = num;
var divIdName = “my”+num+”Div”;
var newdiv = document.createElement(‘div’);
newdiv.setAttribute(“id”,divIdName);
newdiv.innerHTML =
“<tr >”+
“<td > Child </td>”+
“<td >”+
“<select name=”child”+num+”_gender” id=”child”+num+”_gender”>”+
“<option value=”” selected>- -</option>”+
“<option value=”Male”>Male</option>”+
“<option value=”Female”>Female</option>”+
“</select>”+
“</td> ”+
“<td >”+
“<input name=”child”+num+”_dob_mm” type=”text” id=”child”+num+”_dob_mm” style=”width: 30px;” />”+
“ / <input name=”child”+num+”_dob_dd” type=”text” id=”child”+num+”_dob_dd” style=”width: 30px;” />”+
“ / <input name=”child”+num+”_dob_yyyy” type=”text” id=”child”+num+”_dob_yyyy” style=”width: 40px;” />”+
“</td>”+
“ <td ><input name=”child”+num+”_tobacco” type=”checkbox” id=”child”+num+”_tobacco” /></td>”+
“ <td ><input name=”child”+num+”_college” type=”checkbox” id=”child”+num+”_college” /></td>”+
“ <td ><input name=”child”+num+”_hippa” type=”checkbox” id=”child”+num+”_hippa” /></td>”+
“ <td><a href=”javascript:;” onclick=”removeEvent(‘”+divIdName+”‘)”>Remove</a></td>”+
“</tr>”;
ni.appendChild(newdiv);
}
And here is the html code:
[code]
<div id=”myDiv”> </div>
<input type=”hidden” value=”2″ id=”theValue” />
<p><a href=”javascript:;” onclick=”addEvent();”>+Add Child</a></p>
Can anyone tell me what I’m doing wrong here? Seem like I should just be able to continue on and do a request(“child3_gender”) and it should return a value.