Show same page after virtual form submission from javascript - javascript

I have this javascript function
function SaveData(index) {
var myVirtualForm = document.createElement("form");
myVirtualForm.setAttribute('method', "post");
var name = $("#" + index + " a").attr('name');
var url = "http://localhost/my_Project/communicator.php?command=save&id=" + name;
myVirtualForm.setAttribute('action', url);
var iframe = document.getElementById(index + "frame");
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var oTable = innerDoc.getElementById("reporttable");
//alert(oTable.rows.item(0).cells.item(0).innerText);
//gets table
var str = "";
var rowLength = oTable.rows.length;
//gets rows of table
for (i = 0; i < rowLength; i++) {
//loops through rows
var oCells = oTable.rows.item(i).cells;
var cellLength = oCells.length;
for (var j = 0; j < cellLength; j++) {
var cellVal = oCells.item(j).innerText;
var a = "";
var b = a.concat(i.toString(), "_", j.toString());
var obj = document.createElement("input");
obj.setAttribute('type', "text");
obj.setAttribute('name', b);
obj.setAttribute('value', cellVal.toString())
myVirtualForm.appendChild(obj);
}
}
myVirtualForm.submit();
}
After submission we go to communicator.php, but i want to stay on same page, who will not changed.

Related

It always show either one output, either it highlight the keywords or only the alert box,how to achieve both at the same time

//grab all div elements in the pages;
let elt = document.getElementsByTagName("div");
var i;
var b = [];
b[0] = "password";
b[1] = "update";
b[2] = "account";
b[3] = "blocked";
b[4] = "alert";
b[5] = "confirm";
b[6] = "cash";
b[7] = "extra";
b[8] = "subscribe";
b[9] = "sample";
b[10] = "winner";
b[11] = "offer";
b[12] = "promotion";
b[13] = "urgent";
b[14] = "action";
b[15] = "update";
b[16] = "luxury";
b[17] = "limited";
b[18] = "login";
b[19] = "alert";
b[20] = "income";
b[21] = "bonus";
b[22] = "verify";
b[23] = "banking";
b[24] = "lowest";
b[25] = "deal";
b[26] = "unusual log in activity";
function scanDOM() {
//loop for html elements;
for (i = 0; i < elt.length; i++) {
var singleDiv = elt[i];
//loop for keywords;
for (j = 0; j < b.length; j++) {
var str = singleDiv.innerHTML;
if (str.indexOf(b[j]) > -1) {
//if found that the keywords match with the one in array, it will highlight the words;
str = str.replace(b[j], '<span style="background-color:#f6ff00;">' + b[j] + '</span>');
singleDiv.innerHTML = str;
popup();
}
}
}
}
// scan through the pages every 5 seconds;
setInterval(scanDOM, 5000);
//alert message;
function popup() {
alert * ("**WARNING!**");*
}

list.appendChild(TOCEntry) shows type Error: its not a function

function createTOC(){
var list = document.getElementsByTagName("ul");
var headingText;
var TOCEntry;
var i;
for( i=1; i<=10; i++){
headingText = document.getElementById(i);
TOCEntry = document.createElement("li");
TOCEntry = "" + headingText + "";
list.appendChild(TOCEntry);
}
}
list.appendChild(TOCEntry) shows type Error: its not a function.
You can try this out.
First, create a dom element
then assign its innerHTML
then add it to Dom
function createTOC(){
var list = document.getElementById("id of ul");
var headingText;
var TOCEntry;
var i;
for( i=1; i<=10; i++){
headingText = document.getElementById(i);
TOCEntry = document.createElement("li");
TOCEntryData = "" + headingText + "";
TOCEntry.innerHtml = TOCEntryData;
list.appendChild(TOCEntry);
}
}
function createTOC(){
var list = document.getElementsByTagName("ul")[0];
var headingText;
var TOCEntry;
var i;
for( i=1; i<=10; i++){
headingText = document.getElementById(i).innerHTML;
TOCEntry = document.createElement("li");
TOCEntryData = "" + headingText + "";
TOCEntry.innerHTML = TOCEntryData;
list.appendChild(TOCEntry);
}
}

How to trigger default rendering in Sharepoint 2013 List View via JS Link

I'm building a custom layout for a SharePoint list via JS Link...
At the moment I'm rendering all by myself, but for some more complex items (Taxonomy, URLs, etc.) it would be great to be able to trigger the custom rendering of SharePoint.
Is this possible somehow for single field types?
var csListView = csListView || {};
csListView.ListBody = '<div class="datagrid"><table><thead>{LIST_HEADER}</thead>{LIST_BODY}<tfoot><tr><td colspan="{FIELD_COUNT}"><div class="paging">{PAGINATION}</div></td></tr></tfoot></table></div>';
csListView.HeaderRow = '<tr>{HEADER_ITEMS}</tr>';
csListView.HeaderItem = '<th>{HEADER_ITEM}</th>';
csListView.BodyRow = '<tr class="{ALT_CLASS}">{LIST_ITEMS}</tr>';
csListView.BodyItem = '<td>{LIST_ITEM}</td>';
csListView.CustomizeFieldRendering = function ()
{
var fieldJsLinkOverride = {};
fieldJsLinkOverride.Templates = {};
fieldJsLinkOverride.Templates.Body = csListView.RenderBody;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldJsLinkOverride);
};
csListView.RenderBody = function (ctx) {
var colspan = ctx.ListSchema.Field.length;
var html = '';
var itemHtml = '';
var itemsHtml = '';
var rowHtml = '';
var bodyHtml = '';
var paginationHtml = '';
var headerItemsHtml = '';
var headerHtml = '';
//Render Header fields
for (var i = 0; i < ctx.ListSchema.Field.length; i++) {
var sortUrl = location.search + '?SortField=' + ctx.ListSchema.Field[i].RealFieldName + '&SortDir=Desc';//ctx.HttpRoot + ctx.listUrlDir + '/&' + ctx.ListSchema.FieldSortParam
var item = '' + ctx.ListSchema.Field[i].DisplayName + '';
headerItemsHtml += csListView.HeaderItem.replace('{HEADER_ITEM}', ctx.ListSchema.Field[i].DisplayName);
}
headerHtml = csListView.HeaderRow.replace('{HEADER_ITEMS}', headerItemsHtml);
//Go through all rows
for (var i = 0; i < ctx.ListData.Row.length; i++) {
var cssClass = (i % 2 == 0) ? 'alt' : '';
//Go through all fields
itemsHtml = '';
for (var j = 0; j < ctx.ListSchema.Field.length; j++) {
var item = csListView.renderField(ctx, ctx.ListSchema.Field[j], ctx.ListData.Row[i]);
itemHtml = csListView.BodyItem.replace('{LIST_ITEM}',item);
itemsHtml += itemHtml;
}
rowHtml = csListView.BodyRow.replace('{LIST_ITEMS}',itemsHtml);
rowHtml = rowHtml.replace('{ALT_CLASS}', cssClass);
bodyHtml += rowHtml;
}
html = csListView.ListBody.replace('{LIST_BODY}', bodyHtml);
html = html.replace('{PAGINATION}', renderPaging(ctx));
html = html.replace('{FIELD_COUNT}', colspan);
html = html.replace('{LIST_HEADER}', headerHtml);
return html;
};
csListView.renderField = function (ctx, fieldData, rowData) {
return rowData[fieldData.RealFieldName];
}
To change a the view of a field you could use this
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {'ColumnName': { 'View' : '<b><#=ctx.CurrentItem.ColumnName#></b>' }};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
Does that answer your question?

Search and match CSV file values with javascript

I've uploaded a CSV-file to an HTML page via javascript. The CSV rows are: name and email-address, e.g. rambo,rambo#rambo.com.
How to SEARCH the 'name' from these loaded CSV-file?
Also, one of the data is an email-address and I want to send a mail to that email-address. Is that value retrieved to a variable?
My code to search each elements:
function Search() {
var fileUpload = document.getElementById("fileUpload");
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.csv|.txt)$/;
if (regex.test(fileUpload.value.toLowerCase())) {
if (typeof (FileReader) != "undefined") {
var reader = new FileReader();
reader.onload = function (e) {
var table = document.createElement("table");
var rows = e.target.result.split("\n");
for(var i = 0; i < rows.length; i++)
{
var row = table.insertRow(-1);
var cells = rows[i].split(",");
for(var j = 0; j < cells.length; j++)
{
var cell = row.insertCell(-1);
// cell.innerHTML = cells[j];
// Here repeated checkboxes:
var radio = document.createElement('input');
radio.type = 'checkbox';
radio.name = 'check';
}
var ser=document.getElementById("texts");
if(cells[i].indexOf(ser))
{
alert("matches");
cell.innerHTML = cells[i];
}
else
{
alert("unmatches");
}
var cell = row.insertCell(-1);
cell.appendChild(radio);
//cell.appendChild(button);
}
var button = document.createElement('button');
button.textContent = 'Send';
cell.appendChild(button);
button.onclick = function(){ alert();};
var dvCSV = document.getElementById("dvCSV");
dvCSV.innerHTML = "";
dvCSV.appendChild(table);
}
reader.readAsText(fileUpload.files[0]);
}
}
}
Ad search: indexOf() is your friend here. This should give you a figure:
var table = $('#your-table'),
searchstring = 'your-searchstring';
searchstring.toLowerCase();
for (var i = 0, cell; cell = table.cells[i]; i++) {
if (cell.indexOf(searchstring)) {
// I don't know what you want to do with the search-results...
// ..but you can do it here.
}
}
Ad email-address: you can add the address to a variable in your CSV-import:
var cells = rows[i].split(","),
address = cells[1];
I'd suggest making an array addresses and fill it each row.

TypeError: tableObj.appendChild is not a function

var oTable;
$(document).ready(function() {
loadSubMenus();
});
function loadSubMenus() {
var resultStringX = $.ajax({
type : "POST",
url : "getSubMenuList",
dataType : 'text',
async : false
}).responseText;
resultStringX = $.trim(resultStringX);
var o = JSON.parse(resultStringX);
var idArray = new Array();
var nameArray = new Array();
idArray = o.result.subMenuId;
nameArray = o.result.subMenuName;
var tableObj = $("#tableId").val();
var colCount = 0;
var trObj = document.createElement("tr");
for (var i = 0; i < idArray.length; i++) {
var tdObj = document.createElement("td");
var inputElem = document.createElement("input");
inputElem.type = "checkbox";
inputElem.setAttribute("id", "id_"+i);
inputElem.setAttribute("value", idArray[i]);
inputElem.style.marginTop = "-1px";
var spanObj = document.createElement("span");
spanObj.innerHTML = nameArray[i];
tdObj.appendChild(inputElem);
tdObj.appendChild(spanObj);
trObj.appendChild(tdObj);
colCount++;
if (colCount == 5) {
tableObj.appendChild(trObj);
trObj = "";
trObj = document.createElement("tr");
colCount = 0;
}
if (idArray.length < 5) {
if ((idArray.length - 1) == i) {
tableObj.appendChild(trObj);
}
}
}
if(idArray.length/5>0){
tableObj.appendChild(trObj);
}
document.getElementById("subMenuCount").value=idArray.length;
}
am not getting output..
i want to load menu n sub-menu from the database
what is error am nt able to get pls help me
how to solve this.
what i have to do..
what is the error
in another jsp page i created "tableid" so there i defined td
tableObj is not a DOM element. It is the value of $("#tableId").val(). Probably you need to create it also as a DOM element:
var tableObj = document.createElement("table");
...

Categories