Javascript : How access to a local function from global code - javascript

I have a function inside of an immediately invoked function expression and I want to be able to access that function globally without lexically scoping it that way.
How can I access this "private" function through a namespace called "App"?
indew.html:
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="filtering.js"></script>
</head>
<body>
<article>
<p>
Computer graphics is widespread today. Computer imagery is found on televi
surfaces, illumination sources, and so forth, perhaps with a dynamic (time) component".[3]
</p>
</article>
<section id="result"></section>
<script>
App.showOccurenceFiltering(); // here is my wrong call
</script>
</body>
</html>
js script :
var App = (function () {
function showOccurenceFiltering() {
"use strict";
var filteredWordsArray = filtering(),
resultView = "<ol>";
for (var i = 0; i < filteredWordsArray.length; i++) {
var partWord = filteredWordsArray[i].substring(0, filteredWordsArray[i].indexOf(" ")), // de 0 jusqua l espace : la partie mot
partNumber = filteredWordsArray[i].substring(filteredWordsArray[i].indexOf(" ") + 1); // de l'espace à la fin : la partie number
resultView += "<li>" + partWord + " (" + partNumber + ")</li>";
}
resultView += "</ol>";
document.getElementById('result').innerHTML = resultView;
}
}(App));
so i got an error of a miss call like shows the capture :
how should i resolve my problem ??

You'll need to expose the function to the global scope. You can do this with a namespace, like this:
(function () {
function showOccurenceFiltering() {
"use strict";
var filteredWordsArray = filtering(),
resultView = "<ol>";
for (var i = 0; i < filteredWordsArray.length; i++) {
var partWord = filteredWordsArray[i].substring(0, filteredWordsArray[i].indexOf(" ")), // de 0 jusqua l espace : la partie mot
partNumber = filteredWordsArray[i].substring(filteredWordsArray[i].indexOf(" ") + 1); // de l'espace à la fin : la partie number
resultView += "<li>" + partWord + " (" + partNumber + ")</li>";
}
resultView += "</ol>";
document.getElementById('result').innerHTML = resultView;
}
// Prepare a "dummy" object
var obj = {};
// Attach the private function to this object
obj.showOccurenceFiltering = showOccurenceFiltering;
// Attach the dummy object to the global scope in a controlled namespace:
window.App = obj;
}());
Then you can access the function like this:
App.showOccurenceFiltering();

You could do the following:
var App = (function(){
var obj = {};
obj.showOccurenceFiltering = function() {
"use strict";
var filteredWordsArray = filtering(),
resultView = "<ol>";
for (var i = 0; i < filteredWordsArray.length; i++) {
var partWord = filteredWordsArray[i].substring(0, filteredWordsArray[i].indexOf(" ")), // de 0 jusqua l espace : la partie mot
partNumber = filteredWordsArray[i].substring(filteredWordsArray[i].indexOf(" ") + 1); // de l'espace à la fin : la partie number
resultView += "<li>" + partWord + " (" + partNumber + ")</li>";
}
resultView += "</ol>";
document.getElementById('result').innerHTML = resultView;
}
return obj;
}());

Your App variable remains undefined because the Immediately Invoked Function Expression does not return a value.
Instead, define App as an object literal, as follows:
var App = {
showOccurenceFiltering: function() {
"use strict";
var filteredWordsArray = filtering(),
resultView = "<ol>";
for (var i = 0; i < filteredWordsArray.length; i++) {
var partWord = filteredWordsArray[i].substring(0, filteredWordsArray[i].indexOf(" ")), // de 0 jusqua l espace : la partie mot
partNumber = filteredWordsArray[i].substring(filteredWordsArray[i].indexOf(" ") + 1); // de l'espace à la fin : la partie number
resultView += "<li>" + partWord + " (" + partNumber + ")</li>";
}
resultView += "</ol>";
document.getElementById('result').innerHTML = resultView;
}
};
Now your call will be valid.

Related

async functions inside jquery each() loops

I have a loop running for each selected checkbox in Javascript / Jquery.
Inside this loop I call an async function that will return a Tile Layer(Image).
I have to pass to this function a parameter called checkboxPermanent.
After this function is called the variable checkboxPermanent changes its value, not sure why.
In the sequence it calls a similiar function but now passing the same variable but with the wrong parameter value.
$('#exec-perm').on('click', function () {
var checkboxPermanent;
$('#checks-perm input').each(async function () {
checkboxPermanent = $(this).attr('value');
isChecked = $(this).prop('checked');
permanent = permanent_layers[checkboxPermanent] // começa com valor undefined, no próximo loop passa a conter um objeto para que possa cair na codição 1
pixel_permanent = pixel_permanent_layers[checkboxPermanent]
if (permanent) {
if (!isChecked) {
map.removeLayer(permanent)
map.removeLayer(pixel_permanent)
ctrlLayers.removeLayer(permanent)
ctrlLayers.removeLayer(pixel_permanent)
} else if (isChecked && state_faz == faz_value && state_ano_safra == ano_safra_value && state_profundidade == profundidade_value) {
//map.addLayer(permanent)
//map.addLayer(pixel_permanent)
map.removeLayer(permanent)
map.removeLayer(pixel_permanent)
ctrlLayers.removeLayer(permanent)
ctrlLayers.removeLayer(pixel_permanent)
ctrlLayers.addOverlay(permanent, 'Mapa de ' + checkboxPermanent);
ctrlLayers.addOverlay(pixel_permanent, 'Mapa de ' + checkboxPermanent + ' - Pixels');
} else if (isChecked && (state_faz != faz_value || state_ano_safra != ano_safra_value || state_profundidade != profundidade_value)) {
map.removeLayer(permanent)
map.removeLayer(pixel_permanent)
ctrlLayers.removeLayer(permanent)
ctrlLayers.removeLayer(pixel_permanent)
permanent = wmsPermRasterCall(checkboxPermanent, faz_value, profundidade_value);
pixel_permanent = wmsPixelPermCall(checkboxPermanent, faz_value, profundidade_value);
permanent_layers[checkboxPermanent] = permanent; // armazena o valor no array para que possa cair na condicional que irá excluir os layers do control
pixel_permanent_layers[checkboxPermanent] = pixel_permanent;
//map.addLayer(permanent);
//map.addLayer(pixel_permanent);
ctrlLayers.addOverlay(permanent, 'Mapa de ' + checkboxPermanent);
ctrlLayers.addOverlay(pixel_permanent, 'Mapa de ' + checkboxPermanent + ' - Pixels');
}
} else if (isChecked) {
console.log(checkboxPermanent)
permanent = wmsPermRasterCall(checkboxPermanent, faz_value, profundidade_value);
console.log(permanent)
pixel_permanent = wmsPixelPermCall(checkboxPermanent, faz_value, profundidade_value);
//console.log(checkboxPermanent)
permanent_layers[checkboxPermanent] = permanent; // armazena o valor no array para que possa cair na condicional que irá excluir os layers do control
pixel_permanent_layers[checkboxPermanent] = pixel_permanent;
//map.addLayer(permanent);
//map.addLayer(pixel_permanent);
ctrlLayers.addOverlay(permanent, 'Mapa de ' + checkboxPermanent);
ctrlLayers.addOverlay(pixel_permanent, 'Mapa de ' + checkboxPermanent + ' - Pixels');
}
if (checkboxPermanent == 'altimetria') {
leg_permanent[checkboxPermanent] = 'Emp:' + checkboxPermanent + '_' + faz_value
leg_pixel_permanent[checkboxPermanent] = 'Emp:mv_' + checkboxPermanent + '_sql'
} else {
leg_permanent[checkboxPermanent] = 'Emp:' + checkboxPermanent + '_' + faz_value + '_p' + profundidade_value
leg_pixel_permanent[checkboxPermanent] = 'Emp:mv_' + checkboxPermanent + '_sql'
}
});
})
If I console.log(checkboxPermanent) before wmswmsPermRasterCall(). It will return the right value. If I console.log(checkboxPermanent) right after wmswmsPermRasterCall() is called it gets a different value..
async function wmsPermRasterCall(checkboxPermanent, faz_value, profundidade_value) {
//var colorRampSLD = getStyles(faz_value, checkboxPermanent)
if (checkboxPermanent == 'altimetria') {
var raster_name = checkboxPermanent + '_' + faz_value
getColors = await getStyles(faz_value, checkboxPermanent)
var colorEnv = '';
for (var j = 0; j < getColors.length; j++) {
if (j + 1 >= getColors.length) {
colorEnv += 'c' + j + ':' + getColors[j]
} else {
colorEnv += 'c' + j + ':' + getColors[j] + ';'
}
}
return L.tileLayer.wms('http://localhost:8080/geoserver/Emp/wms', {
layers: 'Emp:' + raster_name,
transparent: true,
format: 'image/png',
}).setParams({
env: colorEnv
})
} else {
return L.tileLayer.wms('http://localhost:8080/geoserver/Emp/wms', {
layers: 'Emp:' + checkboxPermanent + '_' + faz_value + '_p' + profundidade_value,
transparent: true,
format: 'image/png',
})
}
}
What Am I missing here?
Check here:
console.log(checkboxPermanent)
permanent = wmsPermRasterCall(checkboxPermanent, faz_value, profundidade_value);
console.log(permanent)
This function is async, it will run outside of your function, your code will continue before wmsPermRasterCall is finished.
You need to wait for the result of wmsPermRasterCall using await:
console.log(checkboxPermanent)
permanent = await wmsPermRasterCall(checkboxPermanent, faz_value, profundidade_value);
console.log(permanent)
Your code will halt until wmsPermRasterCall is finished.

Why eventListener in JavaScript not displaying?

I have been struggling for hours with a simple addEventListener and I really don't understand why.
Find attached my JS code. I am trying to create a cart. I store in a localstorage the products I want to buy. Then I display it on a test page to see if my code was working.
I add a class to each line of the array using i variable.
Then I try to do a simple alert when I click on the link I created with the class. The goal is then to add a link to remove this article from the cart.
I get no error, but the alert does not display.
Plus, when I do
alert(querySelector('.article' + i + '').innerHTML);
it works perfectly, but with the code below it does not :
let url = window.location.search;
let searchUrl = new URLSearchParams(url);
if (searchUrl.has("produit")) {
//Requête fetch
fetch('http://localhost:3000/api/cameras')
.then(function(response) {
return response.json();
})
.then(function(produit) {
produit.forEach(element => {
// Récupération url, conversion string et mise en forme pour recherche
let urlProduit = String(searchUrl.getAll("produit"));
urlProduit = urlProduit.replace("-", " ");
//Affichage du produit
if (urlProduit == element.name) {
document.getElementById('content').innerHTML += '' + element.name + '';
document.getElementById('content').innerHTML += '<p>' + element.description + '</p>';
document.getElementById('content').innerHTML += '<p>' + element.price + '</p>';
document.getElementById('content').innerHTML += ' Ajouter au panier ';
// Gestion du panier
document.getElementById('ajoutPanier').addEventListener('click', function() {
if (localStorage.getItem("panier") == null) {
let panier = {};
panier.produits = [];
localStorage.setItem('panier', JSON.stringify(panier));
alert("Panier créé");
} else {
let panier = JSON.parse(localStorage.getItem("panier"));
panier.produits.push(element);
localStorage.setItem("panier", JSON.stringify(panier));
alert("Ajouté au panier");
}
});
}
})
})
}
//Affichage du panier
if (!localStorage.getItem("panier")) {
document.getElementById('panier').innerHTML += '<p> Votre panier est vide</p>';
}
else {
//Vider le panier
document.querySelector('#panier h2').innerHTML += ' (Vider) ';
document.querySelector('.viderPanier').addEventListener('click', function() {
alert("Panier vidé");
});
let i=0;
let panier = localStorage.getItem("panier");
panier = JSON.parse(panier);
console.log(panier); // A supprimer
panier.produits.forEach(element => {
document.getElementById('panier').innerHTML += '<p><strong>' + element.name + '</strong> - ' + element.price + ' € - Retirer du panier - Position' + i + ' </p>';
document.querySelector('.article' + i + '').addEventListener('click', function() {
console.log("ok");
alert("ok");
})
i++;
})
document.getElementById('panier').innerHTML += 'Passer la commande';
}
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="utf-8">
<title>Page produit</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="content">
Retour à l'acceuil<br>
<h2>Votre produit</h2>
</div>
<div id="panier">
<h2>Votre panier</h2>
</div>
<script src="produit.js" charset="utf-8"></script>
</body>
</html>
I just started JavaScript and eventListener perfectly worked so far. I know it is not the best solution for what I want to create, I am open to tips from you guys.

Save data from an HTML table

I am working with MVC and I am creating a dynamic table as data from # Html.TextBoxFor is added that I have in my view, and all good so far
My question is: Any way to save my table that I create with a JS function?
Searching the web I found some examples but so far nothing works for me
My Table
<table id="mytable" class="table table-bordered table-hover ">
<tr bgcolor="#90A8D0">
<th>Proyecto</th>
<th>Cuenta</th>
<th>Sub Cuenta</th>
<th>Beneficiario</th>
<th>Tipo de Pago</th>
<th>Pago en el proyecto</th>
<th>Pago Por México</th>
<th>Tarjeta Usuario</th>
<th>Total de Remesa</th>
<th>Obersvaciones</th>
<th>Eliminar</th>
</tr>
</table>
So I create my dynamic table:
$(document).ready(function() {
$('#adicionar').click(function () {
debugger;
var Proyecto = $("#ProyectoID option:selected").text();
var Recurso = $("#RecursoID option:selected").text();
var SubRecurso = $("#SubRecursoID option:selected").text();
var Beneficiario = document.getElementById("Beneficiario").value;
var TipoPago = $("#TipoPagoID option:selected").text();
var PagoProyecto = document.getElementById("PagoProyecto").value;
var PagoMexico = document.getElementById("PagoMexico").value;
var TarjetaUsuario = document.getElementById("TarjetaUsuario").value;
var TotalRemesa = parseInt(PagoProyecto) + parseInt(PagoMexico) + parseInt(TarjetaUsuario);
var ObervacionesCuenta = document.getElementById("ObervacionesCuenta").value;
var i = 1; //contador para asignar id al boton que borrara la fila
var fila = '<tr id="row' + i + '"><td>' + Proyecto + '</td><td>' + Recurso + '</td><td>' + SubRecurso + '</td><td>' + Beneficiario + '</td><td>' + TipoPago + '</td><td>' + PagoProyecto + '</td><td>' + PagoMexico + '</td><td>' + TarjetaUsuario + '</td><td>' + TotalRemesa + '</td><td>' + ObervacionesCuenta + '</td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">Quitar</button></td></tr>'; //esto seria lo que contendria la fila
i++;
$('#mytable tr:first').after(fila);
$("#adicionados").text(""); //esta instruccion limpia el div adicioandos para que no se vayan acumulando
var nFilas = $("#mytable tr").length;
$("#adicionados").append(nFilas - 1);
//le resto 1 para no contar la fila del header
document.getElementById("Recurso").value ="";
document.getElementById("SubRecurso").value = "";
document.getElementById("Proyecto").value = "";
document.getElementById("Proyecto").focus();
});
$(document).on('click', '.btn_remove', function () {
var button_id = $(this).attr("id");
//cuando da click obtenemos el id del boton
$('#row' + button_id + '').remove(); //borra la fila
//limpia el para que vuelva a contar las filas de la tabla
$("#adicionados").text("");
var nFilas = $("#mytable tr").length;
$("#adicionados").append(nFilas - 1);
});
});
This is an example I found on the web:
$(function () {
debugger;
$('#mytable').each(function () {
var cuotaNo= $(this).find('td').eq(0).html();
var interes = $(this).find('td').eq(1).html();
var abonoCapital = $(this).find('td').eq(2).html();
var valorCuota = $(this).find('td').eq(3).html();
var saldoCapital = $(this).find('td').eq(4).html();
$.ajax({
async: false,
type: "POST",
url: "../Guardardatos",
data:"cuotaNo="+cuotaNo+"&interes="+interes+"&abonoCapital="+abonoCapital+"&valorCuota="+valorCuota+"&saldoCapital="+saldoCapital,
data: {valores:valores},
success: function(data) { if(data!="");}
});
});
});
As this last example is what I am trying to save the data that is created in my table
In this example, create TableView, TableRowView, and TableCellView classes. Each class returns an object with an element property and render* method. TableView.element uses the table provided in your example. TableRowView.element and TableCellView.element both create new elements.
After the data from the form (not shown in your example) is POSTED and the success callback is executed: first, create a new instance of TableView; second, create a new instance of TableRowView; third, create new instances of TableCellView for each data property, then render the property value inside of it.
To ensure that the correct order of data elements is rendered, use columnOrder to define the table cell names, the iterate over them in the onSuccess callback. Each iteration, use the column name to access the corresponding data property.
const columnOrder = [
'proyecto',
'cuenta',
'subCuenta',
'beneficiario',
'tipoPago',
'pagoProyecto',
'pagoMexico',
'tarjetaUsuario',
'totalRemesa',
'obersvaciones',
'elminar',
]
const TableView = () => {
let table = document.getElementByID('myTable')
return {
element: table,
renderTableRow: (element) => {
this.element.appendChild(element)
return this
}
}
}
const TableRowView = () => {
let tr = document.createElement('tr')
return {
element: tr,
renderTableCell: (element) => {
this.element.appendChild(element)
return this
},
}
}
const TableCellView = () => {
let td = document.createElement('tr')
return {
element: td,
render: (value) => {
this.element.innerHTML = value
return this
},
}
}
const onSuccess = (event) => {
let data = event.data
/*
data
-----
{
'proyecto': ??,
'cuenta': ??,
'subCuenta': ??,
'beneficiario': ??,
'tipoPago': ??,
'pagoProyecto': ??,
'pagoMexico': ??,
'tarjetaUsuario': ??,
'totalRemesa': ??,
'obersvaciones': ??,
'elminar': ??,
}
*/
let table = new TableView()
let row = new TableRow()
columnOrder.forEach((columnName) => {
let cell = new TableCellView()
let cellData = data[columnName]
cell.render(cellData)
row.renderTableCell(cell.element)
table.renderTableRow(row.element)
})
}
$.ajax({
...,
success: onSuccess,
})

innerHTML not printing anything

Im trying some stuff for an exam and I can't make it work. It's really simple and i can't understand why is not working.
<!DOCTYPE html>
<html>
<head>
<title>Exercici 2</title>
<script type="text/javascript">
//rep 2 paràmetres d'entrada i els suma
function suma(a, b) {
alert(arguments.length);
//donaria undefined, ja que no existeix el argument amb índex 2, tindria que ser [1]
alert(arguments[2]);
//3 + 5 = 8
return a + b;
}
var result = suma(3,5);
document.getElementById("result").innerHTML += "<strong>Suma</strong>: 3 + 5 = " + result + "<br>";
</script>
</head>
<body>
<div id="result">
</div>
</body>
</html>
I know alert(arguments[2]); will show undefined.
Issue is you are calling function before DOM is rendered. So result is not available. Move your script after body.
<html>
<head>
<title>Exercici 2</title>
</head>
<body>
<div id="result">
</div>
</body>
<script type="text/javascript">
//rep 2 paràmetres d'entrada i els suma
function suma(a, b) {
//3 + 5 = 8
return a + b;
}
var result = suma(3, 5);
document.getElementById("result").innerHTML += "<strong>Suma</strong>: 3 + 5 = " + result + "<br>";
</script>
</html>
Necesitas un onload para que funcione pues llamas el getElement By Id, antes de que exista el elemento y no tiene sentido. Ademas tu salida debe ser un string.
You need a "onload" function for this case, because you declare your getElemetnById before the element, also your output in your function should be a string.
<script type="text/javascript">
//rep 2 paràmetres d'entrada i els suma
function suma(a, b) {
//a = argumento 0, b = argumento 1
return (a + b).toString();
}
//estas ejecutando esto, sin antes existir el id="result", por tanto debes esperar
// aque primero se cree, y luego ejecutar, eso se hace añadiendo esto:
window.onload = function(){ //espera a que todos los elements html se creen.
var result = suma(3,5);
document.getElementById("result").innerHTML += "<strong>Suma</strong>: 3 + 5 = " + result + "<br>";
}
</script>
When working with Sums, it is advisable to add parseInt,
this way you can also add var result = suma('3', 5); and it will return 8, if you dont have the parseInt and you parse a string '3' it will concat it and will return 35
function suma(a, b) {
//3 + 5 = 8
return parseInt(a) + parseInt(b);
}
var result = suma(3, 5);
document.getElementById("result").innerHTML += "<strong>Suma</strong>: 3 + 5 = " + result + "<br>";

compare special characters with variable javascript

I have a code that compares if a variable that I get is equal to a certain value. So the code is something like this:
if (data[name] == '1222 €'){
ResultField = ResultField + 'Beschrijving van de maningsprocedure: : rekeningoverzichten ' + '<br>';
}
The problem is that what I get is for example '1222 €'. '1222 €' == '1222 €' is false so it won't enter inside the if. And If I put the code like this:
if (data[name] == '1222 €'){
ResultField = ResultField + 'Beschrijving van de maningsprocedure: : rekeningoverzichten ' + '<br>';
}
The code don't even start to execute due to the special character. So how can I do to make '1222 €' == '1222 €' true?
This is all the code that I am using:
$(function() {
setTimeout(function() {
DINK.utils.input.formula.add({
path : 'IbanDrive/Newcollection/eurosymbol',
types : {
'IbanDrive/Newcollection/eurosymbol/FrequentieVanDeManingsprocedure' : 'text',
'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen' : 'text',
'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen2' : 'text',
'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen3' : 'text',
'IbanDrive/Newcollection/eurosymbol/HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden' : 'array',
'IbanDrive/Newcollection/eurosymbol/empty' : 'text',
'IbanDrive/Newcollection/eurosymbol/empty2' : 'text',
'IbanDrive/Newcollection/eurosymbol/empty3' : 'text',
'IbanDrive/Newcollection/eurosymbol/debiteuren' : 'text',
'IbanDrive/Newcollection/eurosymbol/debiteuren2' : 'text',
'IbanDrive/Newcollection/eurosymbol/debiteuren3' : 'text',
'IbanDrive/Newcollection/eurosymbol/BeschrijvingVanDeManingsprocedure' : 'text',
'IbanDrive/Newcollection/eurosymbol/ZoJaVoorWelkBedragAantalDebiteuren' : 'array',
'IbanDrive/Newcollection/eurosymbol/testDim' : 'text'
},
names : {
'IbanDrive/Newcollection/eurosymbol/testDim' : 'testDim'
},
change : {
},
anyChange : function(data) {
var FrequentieVanDeManingsprocedure = 'IbanDrive/Newcollection/eurosymbol/FrequentieVanDeManingsprocedure';
var tijdstipVdagen = 'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen';
var tijdstipVdagen2 = 'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen2';
var tijdstipVdagen3 = 'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen3';
var HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden = 'IbanDrive/Newcollection/eurosymbol/HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden';
var empty = 'IbanDrive/Newcollection/eurosymbol/empty';
var empty2 = 'IbanDrive/Newcollection/eurosymbol/empty2';
var empty3 = 'IbanDrive/Newcollection/eurosymbol/empty3';
var debiteuren = 'IbanDrive/Newcollection/eurosymbol/debiteuren';
var debiteuren2 = 'IbanDrive/Newcollection/eurosymbol/debiteuren2';
var debiteuren3 = 'IbanDrive/Newcollection/eurosymbol/debiteuren3';
var BeschrijvingVanDeManingsprocedure = 'IbanDrive/Newcollection/eurosymbol/BeschrijvingVanDeManingsprocedure';
var ZoJaVoorWelkBedragAantalDebiteuren = 'IbanDrive/Newcollection/eurosymbol/ZoJaVoorWelkBedragAantalDebiteuren';
var testDim = 'IbanDrive/Newcollection/eurosymbol/testDim';
console.log('write this');
var dinkResultField = '';
if (data[FrequentieVanDeManingsprocedure] == 'wekelijks'){
dinkResultField = dinkResultField + 'Frequentie van de maningsprocedure:: wekelijks' + '<br>';
}
if (data[FrequentieVanDeManingsprocedure] == '14 daags'){
dinkResultField = dinkResultField + 'Frequentie van de maningsprocedure:: 14 daags' + '<br>';
}
if (data[FrequentieVanDeManingsprocedure] == 'maandelijks'){
dinkResultField = dinkResultField + 'Frequentie van de maningsprocedure:: maandelijks' + '<br>';
}
if (data[HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden] != undefined){
if (data[HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden].length != 0){
dinkResultField = dinkResultField + 'Heeft u de laatste drie jaar debiteurenverliezen geleden ? : ';
for (i = 0; i < data[HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden].length; i++) {
if (data[HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden][i] == 'ja '){
dinkResultField = dinkResultField + 'ja ';
}
if (data[HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden][i] == 'nee'){
dinkResultField = dinkResultField + 'nee ';
}
}
dinkResultField = dinkResultField + '<br>';
}
}
if (data[ZoJaVoorWelkBedragAantalDebiteuren] != undefined){
if (data[ZoJaVoorWelkBedragAantalDebiteuren].length != 0){
dinkResultField = dinkResultField + 'Zo ja, voor welk bedrag + aantal debiteuren : ';
for (i = 0; i < data[ZoJaVoorWelkBedragAantalDebiteuren].length; i++) {
if (data[ZoJaVoorWelkBedragAantalDebiteuren][i] == 'jaar &#8211 1€'){
dinkResultField = dinkResultField + 'jaar &#8211 1 ';
}
if (data[ZoJaVoorWelkBedragAantalDebiteuren][i] == 'jaar &#8211 2'){
dinkResultField = dinkResultField + 'jaar &#8211 2 ';
}
if (data[ZoJaVoorWelkBedragAantalDebiteuren][i] == 'jaar &#8211 3'){
dinkResultField = dinkResultField + 'jaar &#8211 3 ';
}
}
dinkResultField = dinkResultField + '<br>';
}
}
if (data[BeschrijvingVanDeManingsprocedure] == 'rekeningoverzichten '){
dinkResultField = dinkResultField + 'Beschrijving van de maningsprocedure: : rekeningoverzichten ' + '<br>';
}
if (data[BeschrijvingVanDeManingsprocedure] == 'telefonische maningen '){
dinkResultField = dinkResultField + 'Beschrijving van de maningsprocedure: : telefonische maningen ' + '<br>';
}
if (data[BeschrijvingVanDeManingsprocedure] == 'ingebrekestelling '){
dinkResultField = dinkResultField + 'Beschrijving van de maningsprocedure: : ingebrekestelling ' + '<br>';
}
data[testDim] = dinkResultField;
},
beforeSubmit : function(event, data, params) {
var FrequentieVanDeManingsprocedure = 'IbanDrive/Newcollection/eurosymbol/FrequentieVanDeManingsprocedure';
var tijdstipVdagen = 'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen';
var tijdstipVdagen2 = 'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen2';
var tijdstipVdagen3 = 'IbanDrive/Newcollection/eurosymbol/tijdstipVdagen3';
var HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden = 'IbanDrive/Newcollection/eurosymbol/HeeftUDeLaatsteDrieJaarDebiteurenverliezenGeleden';
var empty = 'IbanDrive/Newcollection/eurosymbol/empty';
var empty2 = 'IbanDrive/Newcollection/eurosymbol/empty2';
var empty3 = 'IbanDrive/Newcollection/eurosymbol/empty3';
var debiteuren = 'IbanDrive/Newcollection/eurosymbol/debiteuren';
var debiteuren2 = 'IbanDrive/Newcollection/eurosymbol/debiteuren2';
var debiteuren3 = 'IbanDrive/Newcollection/eurosymbol/debiteuren3';
var BeschrijvingVanDeManingsprocedure = 'IbanDrive/Newcollection/eurosymbol/BeschrijvingVanDeManingsprocedure';
var ZoJaVoorWelkBedragAantalDebiteuren = 'IbanDrive/Newcollection/eurosymbol/ZoJaVoorWelkBedragAantalDebiteuren';
var testDim = 'IbanDrive/Newcollection/eurosymbol/testDim';
}
});
}, 1300);
});
You need to use the DOM to make your browser render the HTML and then extract the resulting plain text. To do so you can use the techniques explained at Strip HTML from Text JavaScript. Basically, you inject your HTML string into a fake node and call textContent or innerText (older Internet Explorer) from the element's HTML.
Still, beware of differences in white space, accents, case and the like.
I can't speak your language (Dutch?) but you're clearly generating HTML yourself:
dinkResultField = dinkResultField + 'Frequentie van de maningsprocedure:: wekelijks' + '<br>';
Your code basically builds a long HTML string. Most likely, you're trying to parse it at a later stage. Just store data in a convenient format. Instead of:
var amount = "Total: 1234 €";
... do this:
var display = "Total: 1234 €";
var amount = 1234;
Notations like € are HTML escapes for characters and should not be expected to work in JavaScript. Use the characters themselves, as in data[name] == '1222 €' and make sure that you have declared character encoding of the JavaScript file properly. A simple way to achieve this is to write the file with an editor that lets you save it in UTF-8 format with BOM (since BOM, Byte Order Mark, acts as an indication of character encoding).
Should this be impossible for some odd reason, use a JavaScript escape, e.g. as in
data[name] == '1222 \u20AC'

Categories