<< Chennai ColdFusion User Group

Discussion Area

ask questions, discuss topics, solve problems

Discussion Home | About | Threads By Date | Search

Evaluate('form.control') - Error


Thread posted 10/29/09 by krknaveen last edited 10/29/09
8,204 views, 1 comments.

Title
Evaluate('form.control') - Error

Content

I am generating a textbox dynamically using JavaScript.

The Controls donot stay when clicking on the submit button.

The sample code is given belos viz.,

/* ---------- CFM Code Start ---------- */


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Sample Page</title>
    <script language="javascript" type="text/javascript">
        function fnAdd(ContainerId)
        {
            try
            {
                var objParent;
                var objControl;
                var objCountControl;
               
                objCountControl = document.getElementById('CountTextBox');
                objParent = document.getElementById(ContainerId);
               
                objCountControl.value = parseInt(objCountControl.value) + 1;
               
                objControl = document.createElement('input');
                objControl.setAttribute('id', objCountControl.value+'_TextBox');
                objControl.setAttribute('name',objCountControl.value+'_TextBox');
                objControl.setAttribute('value',objCountControl.value);
                objParent.appendChild(objControl);
            }
            catch(err)
            {
                alert("Error Occured (fnAdd): " + err.description);
            }
        }
    </script>
</head>
<body>
    <form method="post">
        <cfoutput>
            <cfif isdefined('SubmitButton')>
            <cfdump var="#form#">
                <cfif isdefined('form.CountTextBox') and form.CountTextBox gt 0>
                    <cfloop index="iCounter" from="1" to="#form.CountTextBox#">
                        #evaluate("form.#iCounter#_TextBox")#
                    </cfloop>
                </cfif>
            </cfif>
           
            <div id="ContainerDiv" style="width: 200px;"></div>
            <input type="button" id="AddButton" name="AddButton" onclick="javascript:fnAdd('ContainerDiv')" value="Add" />
            <input type="submit" id="SubmitButton" name="SubmitButton" value="Submit" />
            <input type="hidden" id="CountTextBox" name="CountTextBox" value="0" />
        </cfoutput>
    </form>
</body>
</html>


/* ---------- CFM Code End ---------- */


Can anyone please help?

Naveen

Comments

posted 10/29/09 by krknaveen | Report Abuse

<p>I have corrected the JavaScript to set the name attribute of the textbox.</p> <p>It works in IE.</p> <p>Naveen</p>