467,859 Members | 1,367 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,859 developers. It's quick & easy.

Element ADDCATEGORY is undefined in FORM.

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
  • viewed: 4331
Share:

Post your reply

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

Similar topics

4 posts views Thread by Timo Nentwig | last post: by
2 posts views Thread by Michael Hill | last post: by
4 posts views Thread by George Hester | last post: by
4 posts views Thread by Stuart Perryman | last post: by
6 posts views Thread by Luke Dalessandro | last post: by
4 posts views Thread by Pasquale | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.