Hi,
The below code is working fine using content editor webpart,but when I fill the form and send it to contactus list,the values are not saved in that list,may I know the reason for that.reply me quick.
Thanks,
Manju
My coding is following as below as:
<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,emailField.value);
}
function SaveInContactUs(Name,Company,Enquiry)
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(‘ContactUs’);
var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = list.addItem(listItemCreationInfo);
newItem.set_item(‘Title’,’Enq’);
newItem.set_item(‘Name’,Name);
newItem.set_item(‘Email’,email);
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>
Well, there might be 1000 and even more reason to have the code broken.
I would recommend to implement a proper error/exception handling with try-catch construction. Check out “google: javascript try catch”, play around and see how it might be used in the current piece of the code. Exception handling would allow us to understand what particular piece of the code fails, why it fails, and how to fix that.
Right now it seems that recommended software engineering practices are not followed, so we have these “I don’t know why it does not work” situations.
Also, it might be suggested to avoid “reply me quick” intentions for the future posts.