Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need Help With Dynamic Row

    Hi,

    I have some code that allows for the creation of a dynamic row to be added and removed by click of a button. I have set so that you can add only 1 extra row and you can also remove that row, but no more than 1 can be added. The code was working fine and on the page that handles that form I was processing the data and making the necessary entries into the database.

    The problem started when I added form validation code. The code is initialized on page load, so I had to add the init function call for the form validation whenever the add row button is clicked. It works fine if it is the first time you tried to submit the form to test for errors. When you click submit again, the browser crashes.

    Code:
    <script type="text/javascript">
    <!--
    function addEvent()
    {
    var ni = document.getElementById('myDiv');
    var numi = document.getElementById('theValue');
    var num = (document.getElementById("theValue").value -1)+ 2;
    numi.value = num;
    var divIdName = "Account "+num;
    var newdiv = document.createElement('div');
    newdiv.setAttribute("id",divIdName);
    newdiv.innerHTML = "<table style=\"WIDTH: 100%\" ....................</table>";
    if(num=1){
    ni.appendChild(newdiv);
    ////////////////////
    this is the init function for the tmt validator
    which is the code in question
    ////////////////////
    tmt_validatorInit();
    
    
    }
    else{
    }
    }
    
    function removeEvent(divNum)
    {
    var numi = document.getElementById('theValue');
    numi.value = 0;
    var d = document.getElementById('myDiv');
    var olddiv = document.getElementById(divNum);
    d.removeChild(olddiv);
    }
    //-->
    </script>
    I am not sure why the browser crashes on the 2nd attempt to press the submit button. It happened every single time i was testing the form validator for catching the errors that it would crash the browser on me.

    Thanks
    Last edited by 7079; 12-14-2006 at 02:00 AM.

  • #2
    New Coder
    Join Date
    Jul 2006
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I actually thought of a better way to word what i was looking for help on.

    It seems that when I submit the form, it initializes the tmt validator. How can write the code so that the validator is initialized only once?

  • #3
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you using Ajax for the submit? I can't speak for everyone but there isn't enough information here for me to make any assessment.

    Maybe you can make a simple test html/javascript file that shows the problem you are having.

    david_kw

  • #4
    New Coder
    Join Date
    Jul 2006
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts
    What do you need to know in order for me to get some help? I will be happy to provide whatever information necessary to find a solution for this problem.

    Thank you in advance

  • #5
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you just post a link to the website with the problem? Then explain exactly what is happening that you don't want to happen. Either that or post an html/javascript file that I can run locally that shows the problem.

    The problem is, for example, that right now you mention your issue happens when you hit submit. Yet in the code you posted I don't see anything about submit. Is addEvent() called when you click submit?

    david_kw


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •