7079
12-14-2006, 12:55 AM
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.
<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
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.
<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