By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,412 Members | 2,835 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,412 IT Pros & Developers. It's quick & easy.

Element ADDCATEGORY is undefined in FORM.

P: 1
addcategory.cfml
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>AddCategory</title>
  6. </head>
  7. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  8.     <script type="text/javascript">
  9.         $(document).ready(function() {
  10.             $('#addCategory').click(function() {
  11.                 var addcategory = $('#category').val();
  12.                 alert('data has been stored to database');
  13.                 $.ajax({
  14.                     type: "POST",
  15.  
  16.                     url: 'addcategory.cfc',
  17.  
  18.                     data: {category: addcategory},
  19.  
  20.                     success: function(data) {
  21.                         alert('data has been stored to database');
  22.                     }
  23.                 });
  24.             });
  25.         });
  26.     </script>
  27. </head>
  28. <body>
  29. <form name="category" id="category" method="post" action="addcategory.cfml">
  30. <tr>
  31.     <td>
  32.          Add Category:
  33.     </td>
  34.  <input type ="text" placeholder ="AddCategory"  name="addcategory" id="addcategory" value="">
  35.  <input type="submit" value="Insert" id="addCategory" />
  36. </tr>
  37.  
  38. <cfquery name="category" datasource="myapp">
  39.             INSERT INTO category(categoryname) VALUES ('#Form.addcategory#')
  40. </cfquery>
  41.  
  42. </body>
  43. <script>
  44.  
  45. </body>
  46. </html>
  47.  
  48.  

addcategory.cfc
Expand|Select|Wrap|Line Numbers
  1. <cfcomponent output="false">
  2.  
  3.     <cffunction name="insertcategory" access="remote" returntype="struct">
  4.         <cfargument name="page" type="numeric" required="yes">
  5.         <cfargument name="pageSize" type="numeric" required="yes">
  6.         <cfset var category=queryNew("")>
  7.  
  8.  
  9.          <cfquery name="category" datasource="myapp">
  10.             INSERT INTO category(categoryname) VALUES ('#Form.addcategory#')
  11.             </cfquery>
  12.             <cfoutput> #inserted# </cfoutput>
  13.  
  14.          <cfreturn QueryConvertForGrid(local.category,
  15.                             ARGUMENTS.page,
  16.                             ARGUMENTS.pageSize)>
  17.     </cffunction>
  18. </cfcomponent>
  19.  
  20.  



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...
Mar 21 '19 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.