Hello-
Could use some help with some form scripts.
I have a page/form which will be sent to pages depending on which checkboxes are checked. Also, there is a script which validates the form when the submit button is clicked, using the onsubmit parameter of the form tag. The action and onsubmit parameters are dynamically written via a javascript.
The html initially sets up the page without input text boxes and a disabled submit button. When the checkbox is clicked and onclick in the tag calls functions that add an appropriately named text box (via innerHtml) and activates the Submit Button. The reverse is true if boxes are unchecked. The script is also to modify the action and onsubmit parameters of the form tag.
The page is not working correctly. In both FireFox and IE8, the action parameter is correctly dynamically written when a checkbox is checked and the link correctly works when the submit button is clicked. However, the fnChkItms function, called by the 'onsubmit' parameter does not run and the link executes without validation.
In FF, using Firebug, the form tag does not have an 'onsubmit' parameter written after a checkbox is checked. In IE8, using Developer Tools, the onsubmit parameter is correctly written, but apparently does not fire.
The page is listed below. The HTML commented out is a hard wired version of the dynamic page, but having only one checkbox line. It works correctly with respect to both action and onsubmit parameters.
Am I missing something, or is the onsubmit parameter not dynamically writable?
TIA for any thoughts and help.
PS--> Note that prmForm.elements[i].checked is using no i instead of including the i because I was getting an error in the post with correct array format. Just add the i back to array to test. I'm new here and don't know how to correct for posting.
<html>
<head>
<script language="JavaScript">
<!--
var bolIsSent = false;
function fnWrite(prmObj, prmForm)
{
var strObjID = prmObj.value;
var intObjID = parseInt(prmObj.value);
document.getElementById("sbtArtDta").disabled = true;
if(prmObj.checked)
{
document.getElementById("nfoCntnr_" + strObjID).innerHTML =
"<input type='text' id='TEXT_" + strObjID + "' name='txt" + strObjID + "'>";
}
else
{
document.getElementById("nfoCntnr_" + strObjID).innerHTML = " ";
}
for (var i=0; i < prmForm.elements.length; i++)
{
if (prmForm.elements i.checked)
{
alert("In OnSubmit, elmnt " + i);
prmForm.onsubmit="return fnChkItms(this)";
prmForm.action="tstWriteTblProc.asp";
break;
}
}
for (var i=0; i < prmForm.elements.length; i++)
{
//re-insert i into array below
if (prmForm.elements[].checked)
{
document.getElementById("sbtArtDta").disabled = false;
break;
}
}
}
function fnChkItms(prmForm)
{
alert("In ChkItms");
if(!bolIsSent)
{
bolIsSent = confirm("The " + prmForm.id + " Will be Submitted");
return (bolIsSent);
}
else
{
return (false);
}
}
-->
</script>
</head>
<body>
<table width="700" align="center" border="1" cellspacing="1" cellpadding="1">
<form method='POST' id='ClntObj_Ordr' name='frmArt' >
<tr>
<td width="150">
Art Type 01
</td>
<td width="15" align="center">
<input type="checkbox" id="checkbox1" name="checkbox1" value="01" onClick="fnWrite(this, this.form)">
</td>
<td align="center" width="530" id="nfoCntnr_01" name="nfoCntnr_01">
</td>
</tr>
<tr>
<td width="150">
Art Type 02
</td>
<td width="15" align="center">
<input type="checkbox" id="checkbox2" name="checkbox2" value="02" onClick="fnWrite(this, this.form)">
</td>
<td align="center" width="530" id="nfoCntnr_02" name="nfoCntnr_02">
</td>
</tr>
<tr>
<td width="150">
Art Type 03
</td>
<td width="15" align="center">
<input type="checkbox" id="checkbox3" name="checkbox3" value="03" onClick="fnWrite(this, this.form)">
</td>
<td align="center" width="530" id="nfoCntnr_03" name="nfoCntnr_03">
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td align="center" colspan="3" id="SbtBtn" name="SbtBtn">
<input type='submit' value='Submit Art Data' id='sbtArtDta' name='sbtArtDta' disabled='true'>
</td>
</tr>
</form>
</table>
<!--
<table width="700" align="center" border="1" cellspacing="1" cellpadding="1">
<form action='tstWriteTblProc.asp' method='POST' id='frmArt' name='frmArt' onsubmit="return fnChkItms(this)">
<tr>
<td width="150">
Art Type 0X
</td>
<td width="15" align="center">
<INPUT type="checkbox" id=checkbox4 name=checkbox4>
</td>
<td align="center" width="530" id="nfoCntnr_01" name="nfoCntnr_01">
<input type='text' id='TEXT_0X' name='txt0X'>
</td>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td align="center" colspan="3">
<input type='submit' value='Submit Art Data' id='sbtArtDta' name='sbtArtDta'>
</td>
</tr>
</form>
</table>
-->
</body>
</html>