/    Sign up×
Community /Pin to ProfileBookmark

What am I doing wrong here?

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 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Child&nbsp;&nbsp;&nbsp;&nbsp;</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”+
“<td >”+
“<input name=”child”+num+”_dob_mm” type=”text” id=”child”+num+”_dob_mm” style=”width: 30px;” />”+
“&nbsp;/ <input name=”child”+num+”_dob_dd” type=”text” id=”child”+num+”_dob_dd” style=”width: 30px;” />”+
“&nbsp;/ <input name=”child”+num+”_dob_yyyy” type=”text” id=”child”+num+”_dob_yyyy” style=”width: 40px;” />”+
“</td>”+
“&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td ><input name=”child”+num+”_tobacco” type=”checkbox” id=”child”+num+”_tobacco” /></td>”+
“&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td ><input name=”child”+num+”_college” type=”checkbox” id=”child”+num+”_college” /></td>”+
“&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td ><input name=”child”+num+”_hippa” type=”checkbox” id=”child”+num+”_hippa” /></td>”+
“&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td><a href=”javascript:;” onclick=”removeEvent(‘”+divIdName+”‘)”>Remove</a></td>”+
“</tr>”;
ni.appendChild(newdiv);
}
[/code]

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>
[/code]

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.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 19.2006 — no offence, but for me, the main wrong thing is that you do not use DOM methods to create/append elements. google for DOM, and you might find the answer.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html

http://www.w3schools.com/htmldom/default.asp

http://www.quirksmode.org/dom/w3c_html.html

...
×

Success!

Help @dirt29 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...