/    Sign up×
Community /Pin to ProfileBookmark

error retrieving id

Hi I tryiing to modify a function that takes a number as a parameter and creates n Number of divs. The function uses insertBefore as a reference for where to insert the new code in the document. I am referencing a div layer “myDiv”, which is fine, but when the insertBefore function runs it can’t find the same div layer. Anyone have any suggestion? Thanks.

[CODE]function showAttendeesNew()
{
var mydiv = false;
var div = false;
var from = document.form;
var html = false;
var count = from.num_of_attend[from.num_of_attend.selectedIndex].value;
for (i = 1; i <= count; i++)
{
mydiv = document.getElementById(“myDiv”);
alert(mydiv);

div = document.createElement(“div”);
//div.setAttribute(“name”, “student”+i);
//div.setAttribute(“id”, “student”+i);
document.body.insertBefore(div, mydiv);
html = ‘<table width=”200″ style=”float:left;”>’;
html+= ‘<tr><td><label for=”fname”>First Name:</label><br /><input type=”text” id=”fname[]” name=”fname” /></td></tr>’;
html+= ‘<tr><td><label for=”lname”>Last Name:</label><br /><input type=”text” id=”lname[]” name=”lname” /></td></tr>’;
html+= ‘<tr><td><label for=”email”>Email:</label><br /><input type=”text” id=”email” name=”email[]” class=”required validate-email” title=”Enter your username” /></td></tr>’;
html+= ‘<tr><td><label for=”credits”><input type=”checkbox” id=”credits” name=”credits” />Would you like to receive Continuing Education Credit?</label></td></tr>’;
html+= ‘<tr id=”rec_credit_license”><td>License Number:<br /><input type=”text” value=”” name=”lic_num[]” size=”20″ maxlength=”30″ /></td> </tr>’;
html+= ‘</table>’;
div.innerHTML = html;

}

}[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@LogicianMay 30.2006 — Hi I tryiing to modify a function that takes a number as a parameter and creates n Number of divs. The function uses insertBefore as a reference for where to insert the new code in the document. I am referencing a div layer "myDiv", which is fine, but when the insertBefore function runs it can't find the same div layer. Anyone have any suggestion? Thanks.[/quote]What is the exact error message that you are getting?
Copy linkTweet thisAlerts:
@cream_cakesauthorMay 30.2006 — Thanks for your reply but I am a bit confused. I have a hard coded div called myDiv. I am then using createElement to create a new div, referenced by the var div. Why is it not attached to the document?
Copy linkTweet thisAlerts:
@James_GatkaMay 30.2006 — cream cakes:

Please check your private messages.
×

Success!

Help @cream_cakes 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.20,
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,
)...