J
jmark
I am generating dynamic forms by overwriting an existing form but I am
getting an unexpected behaviour.
I have the code like shown blow
<div id="formWarpper">
<script type="text/javascript>
function verifyform() {
if (document.form1.text1.value == '') {
alert("text1 value is empty");
}
}
</script>
<form name=form1 onsubmit="return verifyform()>
<input type=text name=text1>
<input type=submit value=Submit>
</form>
</div>
I then create a new form dynamically after an ajax call as shown below
and replace the contents of formWrapper with the new form
document.getElementById(formWarpper).innerHTML= '
<script type="text/javascript>
function verifyform() {
if (document.form2.text2.value == '') {
alert("test2 value is empty");
}
}
</script>
<form name=form2 onsubmit="return verifyform()>
<input type=text name=text2>
<input type=submit value=Submit>
</form>';
The screen is replaced with the new form. If I click View->Page Source
in FF, I see the code for the old form but if I click inspect in
firebug I see the code for the new form.
if I click submit on the new form I get an error
document.form1.text1 has no properties (which is for the old form)
Why is the code for the old form being called while that form is no
longer active? What can I do to stop this error. That is when the
screen is showing the new form, I should not expect any code in the
old form to be loaded.
Thanks
John
getting an unexpected behaviour.
I have the code like shown blow
<div id="formWarpper">
<script type="text/javascript>
function verifyform() {
if (document.form1.text1.value == '') {
alert("text1 value is empty");
}
}
</script>
<form name=form1 onsubmit="return verifyform()>
<input type=text name=text1>
<input type=submit value=Submit>
</form>
</div>
I then create a new form dynamically after an ajax call as shown below
and replace the contents of formWrapper with the new form
document.getElementById(formWarpper).innerHTML= '
<script type="text/javascript>
function verifyform() {
if (document.form2.text2.value == '') {
alert("test2 value is empty");
}
}
</script>
<form name=form2 onsubmit="return verifyform()>
<input type=text name=text2>
<input type=submit value=Submit>
</form>';
The screen is replaced with the new form. If I click View->Page Source
in FF, I see the code for the old form but if I click inspect in
firebug I see the code for the new form.
if I click submit on the new form I get an error
document.form1.text1 has no properties (which is for the old form)
Why is the code for the old form being called while that form is no
longer active? What can I do to stop this error. That is when the
screen is showing the new form, I should not expect any code in the
old form to be loaded.
Thanks
John