Here are the steps,
Create a team site

Open Visual studio, then Create a Empty SharePoint 2013 project and Add a Visual Webpart.

Now open the CRUDJS.aspx page.
First step is to insert some data into the SharePoint list.
HTML Code

Open Visual studio, then Create a Empty SharePoint 2013 project and Add a Visual Webpart.

Now open the CRUDJS.aspx page.
First step is to insert some data into the SharePoint list.
HTML Code
- <div id="insert">
- <table>
- <tr>
- <td> Employee Name: </td>
- <td>
- <input type="text" id="txtname" placeholder="Employee Name" /> </td>
- </tr>
- <tr>
- <td> Designation: </td>
- <td>
- <input type="text" id="txtdesignation" placeholder="Employee Name" /> </td>
- </tr>
- <tr>
- <td></td>
- <td>
- <button type="button" id="buttoninsert" onclick="insert()">Insert</button>
- </td>
- </tr>
- </table>
- </div>
JS
- var siteurl = '/sites/JS';
- function insert()
- {
- var clientContext = new SP.ClientContext(siteurl); // Get SPSITEURL
- var list = clientContext.get_web()
- .get_lists()
- .getByTitle('Employee'); // Get SP list
- var itemCreateInfo = new SP.ListItemCreationInformation();
- var value1 = document.getElementById('txtname')
- .value;
- /Get value from input element
- var value2 = document.getElementById('txtdesignation')
- .value;
- /Get value from input element
- this.oListItem = list.addItem(itemCreateInfo);
- /Adding list items
- oListItem.set_item('Title', value1);
- oListItem.set_item('designation', value2);
- oListItem.update();
- clientContext.load(oListItem);
- clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
- }
- function onQuerySucceeded()
- {
- alert('Item created Successfully');
- }
- function onQueryFailed(sender, args)
- {
- alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
- }




yekula RajaPosted May 22, 2020, 2:49 AM
Thank you for sharing the details.
Vinodh NarayananPosted Dec 12, 2015, 12:29 PM
Thanks
Ankur MistryPosted Dec 12, 2015, 11:20 AM
nice share