Using Ecmascript\Javascript Client Object model – SharePoint 2010
cf21 |
For Testing paste the below in content editor webpart and change the Contact Us list Name.
<script type="text/ecmascript">
function SendEnquiry()
{
var NameField = document.getElementById("Name");
var companyField = document.getElementById("Company");
var emailField = document.getElementById("email");
var enquiryField = document.getElementById("Enquiry");
SaveInContactUs(NameField.value,companyField.value,enquiryField.value);
}
function SaveInContactUs(Name,Company,Enquiry)
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Contact Us');
var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = list.addItem(listItemCreationInfo);
newItem.set_item('Title', 'Enq');
newItem.set_item('Name',Name);
newItem.set_item('Company',Company);
newItem.set_item('Enquiry',Enquiry);
newItem.update();
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
alert('Added!'); }
function failed(sender, args) {
alert('failed. Message:' + args.get_message()); }
</script>
<table><tbody>
<tr><td>Name</td>
<td><input type="text" id="Name" name="Name"/></td>
</tr>
<tr><td>Company</td>
<td><input type="text" id="Company" name="Company"/></td>
</tr>
<tr><td>E-mail</td>
<td><input type="text" id="email" name="E-mail"/></td>
</tr>
<tr><td>Enquiry</td>
<td><input type="text" id="Enquiry" name="Enquiry"/></td>
</tr>
<tr><td><input type="submit" onclick="Javascript:SendEnquiry();" value="Send"/></td></tr>
</tbody></table>
Once done you can fill-up the Form and click Send and check the Contact Us list for details.
Make sure you have a Contact Us list created in your Site with the columns {Name, Company,email,Enquiry} used in this example.
Thank you! Thank you! I've been looking all over for something nice and simple liek this. Set up an alert on the list to send email and viola! Great post!
ReplyDelete