Sunday, 11 September 2016

Building a Registration/Sign Up Solution in SharePoint

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>
<div id="readDiv">
<table>
<tr><td>Country</td><td><select id="country" style="max-width:90%;"></select></td></tr>
<tr><td>state</td><td><select id="state" style="max-width:90%;"></select></td></tr>
<tr>
<td>Comments</td>
<td>
<textarea id="txtComments" style="max-width:90%;"></textarea>
</td>
</tr>
<tr><td><button type="button" id="btnSubmit">Submit</button> </td></tr>
<tr><td> <a href="javascript:printPDF()">Export to PDF</a> </td></tr>
</table>
</div>
</body>
<script>
$(document).ready(function () {
//Load default values-Start
$('#country').append($('<option>', {
value: 0,
text: '--Select Country--'
}));
$('#state').append($('<option>', {
value: 0,
text: '--Select state--'
}));
//Load default values-End
//With out ID
//$().SPServices({
// operation: "GetListItems",
// async: false,
// listName: "state",
// CAMLViewFields: "<ViewFields><FieldRef Name='Title'/></ViewFields>",
// completefunc: function (xData, Status) {
// $(xData.responseXML).SPFilterNode("z:row").each(function () {
// var liHtmlbi = "<option><a href='#' title=''>" + $(this).attr("ows_Title") + "</a></option>";
// $("#state").append(liHtmlbi);
// });
// }
//});
//With ID
$().SPServices({
operation: "GetListItems",
async: false,
listName: "state",
CAMLViewFields: "<ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var liHtmlbi = "<option value='" + $(this).attr("ows_ID") + "'>" + $(this).attr("ows_Title") + "</option>";
$("#state").append(liHtmlbi);
});
}
});
//With out ID
//$().SPServices({
// operation: "GetListItems",
// async: false,
// listName: "Country",
// CAMLViewFields: "<ViewFields><FieldRef Name='Title'/></ViewFields>",
// completefunc: function (xData, Status) {
// $(xData.responseXML).SPFilterNode("z:row").each(function () {
// var liHtmlbi = "<option><a href='#' title=''>" + $(this).attr("ows_Title") + "</a></option>";
// $("#country").append(liHtmlbi);
// });
// }
//});
//With ID
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Country",
CAMLViewFields: "<ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var liHtmlbi = "<option value='" + $(this).attr("ows_ID") + "'>" + $(this).attr("ows_Title") + "</option>";
$("#country").append(liHtmlbi);
});
}
});
$("#btnSubmit").click(function () {
var title = $('#country :selected').text();
var country = $("#country").val();
var state = $("#state").val();
var comments = $("#txtComments").val();
AddItemtolist(title, country, state, comments);
});
function AddItemtolist(title, country, state, comments) {
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: "AllReq",
valuepairs: [["Title", title], ["Country", country], ["state", state], ["Comments", comments]],
completefunc: function (xData, Status) {
if (Status.toLowerCase() == "success") {
window.location.replace("../Lists/AllReq/AllItems.aspx");
//alert("New request has added.");
} else {
alert("Something went wrong!");
}
}
});
}
});
</script>
<script>
function printPDF() {
if (!window.print) {
alert("You need NS4.x to use this print button!")
return
}
window.print()
}
</script>
</html>
view raw gistfile1.txt hosted with ❤ by GitHub