Dynamic forms and functions

M

Marco

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;
}
 
R

RobG

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.
 
M

Marco

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top