/    Sign up×
Community /Pin to ProfileBookmark

Dynamic Forms

Hey folks,

So I had this developer who wrote up an “addElement” function for a dynamic form. The function worked well, however, I tried to add a function to the element and can’t get it working. Does anyone know how to get this working?
I tried to append the element as a child, to an element names “parentid”, defined as

<input id=”parentid” name=”parentid” type=”hidden”>

Here’s the function that I can’t get to work. We’re using alert() to just get this working, but have a different function to use later.

Many thanks beforehand for your time and patience in trying to help me out.
Also, if there is a better way for me to write this code and you have any suggestions, I’m all ears.

thanks,
-marco

[CODE]

function addFormField1(a,b) {
var id = document.getElementById(“id”).value;
$(“#div” + a + “”).append(“<p id=’row” + id + “‘><label for=’txt” + id + “‘> &nbsp;&nbsp;<input type=’text’ size=’43’ onkeyup=’alert(‘” + a + “” + id + “‘);’ name='” + a + “[]’ id='” + a + “” + id + “‘>&nbsp;&nbsp;<a href=’#’ onClick=’removeFormField1(“#row” + id + “”); return false;’><img src=’images/01_03.gif’ border=’0′ ></a><p>”);
$(‘#row’ + id).highlightFade({speed:1000});

//document.getElementById(“parentid”).appendChild(“‘”+ a + “” + id+”‘”);

id = (id – 1) + 2;
document.getElementById(“id”).value = id;
}
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 24.2008 — 
I tried to append the element as a child, to an element names "parentid", defined as

<input id="parentid" name="parentid" type="hidden">

[/QUOTE]


So called [I]empty elements[/I] (input, br, img...) may not have childNodes, thus you can append nothing to them. You may, eventually, insert the elements before the next sibling element, so that you need the nextSibling and insertBefore() methods.

Anyway, the code you have posted is not native javascript, it looks like a part of a framework (JQuery, Protototype or whichever...), so that is impossible for us to give you a solution without knowing what in fact those custom methods (append(), highlightFade()...) suppose to do. And appendChild() method needs an element to be appended, not a string. Better learn javascript and DOM instead (or before) using frameworks.
×

Success!

Help @ywirasin 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...