4

I'm making a website mostly to get better at coding but I recently got into problem which I can't figure out how to solve.

Code:

$("#user-admin-notification-area").blur(function() {
   alert(events[__event].text);
   if(this.value == '')
      $ePreview.html(events[__event].text);
   $ePreview.html(this.value);
});

Code above sets $ePreview html to empty string instead of actual expected html while alert gives proper output... I tested same code in console but there it's ok. (by same code I mean $ePreview.html(events[__event].text).

Events's value:

[
    {
        "id": "2",
        "name": "pozostały czas",
        "start": "0000-00-00 00:00:00",
        "end": "2016-01-31 23:59:59",
        "text": "<b>Uwaga!</b> Jeszcze <span data-end=\"1451606399\" data-reload=\"false\"></span> do końca składania zgłoszeń! Śpiesz się!",
        "type": "5",
        "closeable": "1"
    },
    {
        "id": "3",
        "name": "test",
        "start": "0000-00-00 00:00:00",
        "end": "0000-00-00 00:00:00",
        "text": "I should NOT be displayed! :)",
        "type": "5",
        "closeable": "1"
    },
    {
        "id": "4",
        "name": "test #2",
        "start": "2015-11-08 23:59:59",
        "end": "2015-11-30 23:59:59",
        "text": "Hi m8!",
        "type": "5",
        "closeable": "0"
    }
]
2
  • 1
    So the alert(event); is giving you a error or alert(events[event]); ? Commented Nov 14, 2015 at 20:39
  • @EndritShala none of these any more. Please look at edited question. Commented Nov 14, 2015 at 20:41

1 Answer 1

1

Your code doesn't make sense. If this.value is empty, then you set the html to be events[__event].text, but then you set back the empty value in the next line ($ePreview.html(this.value);). It should be something like:

$("#user-admin-notification-area").blur(function() {
   alert(events[__event].text);
   if(this.value == '')
      $ePreview.html(events[__event].text); 
   else 
      $ePreview.html(this.value);
});
Sign up to request clarification or add additional context in comments.

Comments

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.