0

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 &euro;' 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 &euro;' 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&euro;'){
                    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);

});
4
  • 1
    It's extremely tricky to compare strings as HTML ignoring HTML semantics. Can't you just read the values as plain text? How does that HTML get into your variable in the first place? Commented Sep 24, 2014 at 9:56
  • How can I read the values as plain text? The variable is filled in when I select a certain value in a radio button. When I do that an event is fired and there I have the peace of code I wrote above. And I can use the data object where I can find the value of the selected radio button but it gives me the value with special characters. Commented Sep 24, 2014 at 10:10
  • We'd need to see some code (a vague description of the overall process is probably not enough to answer that question) but I suspect you're using page contents to store data, rather than using a more practical storage system (form controls, data attributes, cookies, localStorage...). Also, will you ever have 1222 € vs $ 1222 or you're just interested in the raw number? Commented Sep 24, 2014 at 10:24
  • You should not have to deal with &euro; in JavaScript ever. Where are you getting this value from? Commented Sep 24, 2014 at 10:53

2 Answers 2

1

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 &euro;";

... do this:

var display = "Total: 1234 &euro;";
var amount = 1234;
Sign up to request clarification or add additional context in comments.

Comments

0

Notations like &euro; 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'

1 Comment

I just use the normal characters (So I used € instead of &euro;) and save the file in UTF-8 with BOM and now it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.