By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Dynamic forms and functions

P: n/a
Hey folks,

Really could use some advice on a function. The code works fine in
creating the element, however, the associated function to the
dynamically added element doesn't run. If you can suggest a way to fix
this or a better way to code this function, I'd really be
appreciative. I've been struggling with all different things. I even
tried defining a parentid as <input id="parentid" name="parentid"
type="hidden"and appending a child. It didn't work.

Any thoughts?

thanks,
-m

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;<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;
}
Sep 23 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sep 24, 7:10*am, Marco <marco.wirasin...@gmail.comwrote:
Hey folks,

Really could use some advice on a function. The code works fine in
creating the element, however, the associated function to the
dynamically added element doesn't run. If you can suggest a way to fix
this or a better way to code this function, I'd really be
appreciative. I've been struggling with all different things. I even
tried defining a parentid as <input id="parentid" name="parentid"
type="hidden"and appending a child. It didn't work.
Not surprising - input elements don't have any content and can't have
child nodes, so they can't be parents.

Any thoughts?
A few. :-)

function addFormField1(a,b) {
* * * * var id = document.getElementById("id").value;
* * * * $("#div" + a + "").append("<p id='row" + id + "'><labelfor='txt" +
This code appears to require a library where a $ function has been
identified. If you want help with a specific library, post your
question in a forum that supports that library.

id + "'&nbsp;&nbsp;<input type='text' size='43' onkeyup='alert('"+
a + "" + id + "');' name='" + a + "[]' id='" + a + "" + id +
"'>&nbsp;<a href='#' onClick='removeFormField1(\"#row" + id + "\");
The for attribute of the label doesn't seem to match the id of the
input.
--
Rob
Sep 23 '08 #2

P: n/a
Hey Rob, et al,

Thanks for pointing out the error. A developer from Odesk got things
work, despite the more-to-be-desired coding of our prior developer.

he used the following line to get things working:

document.getElementById(a + "" + id).onkeyup = function()
{ alert('hi'); };

thought i'd share back. Everything else works fine.

Many thanks again.

cheers,
-m
Sep 24 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.