Dynamic forms and functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marco

    #1

    Dynamic forms and functions

    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"an d appending a child. It didn't work.

    Any thoughts?

    thanks,
    -m



    function addFormField1(a ,b) {
    var id = document.getEle mentById("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='remove FormField1(\"#r ow" + id + "\");
    return false;'><img src='images/01_03.gif' border='0' ></a><p>");
    $('#row' + id).highlightFa de({speed:1000} );

    //document.getEle mentById("paren tid").appendChi ld("'"+ a + "" + id
    +"'");

    id = (id - 1) + 2;
    document.getEle mentById("id"). value = id;
    }
  • RobG

    #2
    Re: Dynamic forms and functions

    On Sep 24, 7:10 am, Marco <marco.wirasin. ..@gmail.comwro te:
    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"an d 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.getEle mentById("id"). value;
            $("#div" + a + "").append( "<p id='row" + id + "'><labelfor='t xt" +
    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='remove FormField1(\"#r ow" + id + "\");
    The for attribute of the label doesn't seem to match the id of the
    input.


    --
    Rob

    Comment

    • Marco

      #3
      Re: Dynamic forms and functions

      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.getEle mentById(a + "" + id).onkeyup = function()
      { alert('hi'); };

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

      Many thanks again.

      cheers,
      -m

      Comment

      Working...