Element ADDCATEGORY is undefined in FORM.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhurii
    New Member
    • Mar 2019
    • 1

    Element ADDCATEGORY is undefined in FORM.

    addcategory.cfm l
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>AddCategory</title>
    </head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#addCategory').click(function() {
                    var addcategory = $('#category').val();
    				alert('data has been stored to database');
                    $.ajax({
                        type: "POST",
                               
                        url: 'addcategory.cfc',
    					
                        data: {category: addcategory},
    					
                        success: function(data) {
                            alert('data has been stored to database');
                        }
                    });
                });
            });
        </script>
    </head>
    <body>
    <form name="category" id="category" method="post" action="addcategory.cfml">
    <tr>
        <td>
             Add Category:
        </td>
     <input type ="text" placeholder ="AddCategory"  name="addcategory" id="addcategory" value="">
     <input type="submit" value="Insert" id="addCategory" />
    </tr>
    
    <cfquery name="category" datasource="myapp">
    		    INSERT INTO category(categoryname) VALUES ('#Form.addcategory#')
    </cfquery>
    
    </body>
    <script>
    
    </body>
    </html>

    addcategory.cfc
    Code:
    <cfcomponent output="false">
    
        <cffunction name="insertcategory" access="remote" returntype="struct">
    	    <cfargument name="page" type="numeric" required="yes">
            <cfargument name="pageSize" type="numeric" required="yes">
            <cfset var category=queryNew("")>
    		 
    		 
    		 <cfquery name="category" datasource="myapp">
    		    INSERT INTO category(categoryname) VALUES ('#Form.addcategory#')
    			</cfquery>
    			<cfoutput> #inserted# </cfoutput>
    			
    		 <cfreturn QueryConvertForGrid(local.category,
                                ARGUMENTS.page,
                                ARGUMENTS.pageSize)>
    	</cffunction>
    </cfcomponent>



    I have been trying to insert values into sql table using ajax,jquery and cfml. Though the values are been inserted its throwing an error before insertion.
    looking for the solution, Thanks in advance...
Working...