JavaScript Uncaught SyntaxError: Unexpected reserved word uncaught syntaxerror unexpected token ' ',uncaught syntaxerror unexpected identifier,

I have this code in JQUERY:

var large='<div class="vip" style ="background:url(./uploads/deal/"+data[a].id+"_1.jpg);">
           <span class ="coundtown" value ='+data[a].deal_time_off+' style ="display:none;"></span>
          <script> $(document).ready(function(){ $('+data[a].deal_unique_id+').countdown({ date:'+data[a].deal_time_off+'}); }); </script>
       <div class = "deal_info clearfix">
           <div class = "deal_subject clearfix">
               <a target='_blank' href="./deal/'+data[a].deal_unique_id+'">adsfd</a>
           </div>
           <div style = "clear:both"></div>
           <div class="timer">
             <img class="img" src="./img/stopwatch.png" border="none" />
             <span class ='+data[a].deal_unique_id+'></span>
           </div>
         </div>
         <div class="percent_mini"></div>
     </div>';
        //$("#left_row").append(large);

But on this line:

 <span class ="coundtown" value ='+data[a].deal_time_off+' style ="display:none;">

I get this error:

Uncaught SyntaxError: Unexpected reserved word

what is the problem?

var large='<div class="vip" style ="background:url(http://mydeal.ge/uploads/deal/"+data[a].id+"_1.jpg);">
           <span class ="coundtown" value ="'+data[a].deal_time_off+'" style ="display:none;"></span>
          <script> $(document).ready(function(){ $("'+data[a].deal_unique_id+'").countdown({ date:"'+data[a].deal_time_off+'"}); }); </script>
       <div class = "deal_info clearfix">
           <div class = "deal_subject clearfix">
               <a target='_blank' href="http://mydeal.ge/deal/'+data[a].deal_unique_id+'">adsfd</a>
           </div>
           <div style = "clear:both"></div>
           <div class="timer">
             <img class="img" src="http://mydeal.ge/img/stopwatch.png" border="none" />
             <span class ="'+data[a].deal_unique_id+'"></span>
           </div>
         </div>
         <div class="percent_mini"></div>
     </div>';

i fixed this variable but still getting error

Answer:1

You can't have newlines in javascript strings without escaping them:

var str1 = "abcd
            efgh";

should be:

var str1 = "abcd\
            efgh";

Your HTML is spread out over multiple lines so you need to escape the line breaks:

var large='<div class="vip" style ="background:url(./uploads/deal/"+data[a].id+"_1.jpg);">\
       <span class ="coundtown" value ='+data[a].deal_time_off+' style ="display:none;"></span>\
      <script> $(document).ready(function(){ $('+data[a].deal_unique_id+').countdown({\ date:'+data[a].deal_time_off+'}); }); </script>\
   <div class = "deal_info clearfix">\
       <div class = "deal_subject clearfix">\
           <a target='_blank' href="./deal/'+data[a].deal_unique_id+'">adsfd</a>\
       </div>\
       <div style = "clear:both"></div>\
       <div class="timer">\
         <img class="img" src="./img/stopwatch.png" border="none" />\
         <span class ='+data[a].deal_unique_id+'></span>\
       </div>\
     </div>\
     <div class="percent_mini"></div>\
 </div>';
Answer:2

Don't use html in a variable, much less a script containing html, because it's most difficult to maintenance. do you should use template (Handlebars, undersscore, mustache, ...). good luck!

Ex:

    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

      <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.min.js"></script>

      <title>your title</title>
    </head>
    <body>
     <script id="our-tpl" type="text/x-handlebars-template">
      <div class="vip" style ="background:url(./uploads/deal{{deal_unique_id}}_1.jpg);"> 
        <span class ="coundtown" value="{{deal_time_off}}" style ="display:none;"></span>
        <div class = "deal_info clearfix">
          <div class = "deal_subject clearfix">
            <a target='_blank' href="./deal/{{deal_unique_id}}">adsfd</a>
          </div>
          <div style = "clear:both"></div>
          <div class="timer">
            <img class="img" src="./img/stopwatch.png" border="none" />
            <span class ="{{deal_unique_id}}"></span>
          </div>
        </div>
        <div class="percent_mini"></div>
      </div>
    </script>
    <div class="render"></div>


    <script type="text/javascript">
      var obj = {deal_unique_id: 1, deal_time_off: "This is your count"},
          tpl =  Handlebars.compile(($('#our-tpl').html())),
          $rend = $('.render');
          //render
          $rend.html(tpl(obj));
      $('.vip').ready(function(){ 
        var el = '.'+obj.deal_unique_id;
        $(el).countdown({ date:obj.deal_time_off}); 
      }); 
    </script>

    </body>
    </html>
Answer:3

I have implemented Login with Facebook successfully and now trying to implement logout option. Included script https://connect.facebook.net/en_US/all.js Invoked JavaScript FB.logout(); as per https:/...

I have implemented Login with Facebook successfully and now trying to implement logout option. Included script https://connect.facebook.net/en_US/all.js Invoked JavaScript FB.logout(); as per https:/...

Trying to make a progress bar for a form upload (old HTML4 form upload, not new HTML5 API). The progress actually tracks additional work being done after the file has moved. The way it has been ...

Trying to make a progress bar for a form upload (old HTML4 form upload, not new HTML5 API). The progress actually tracks additional work being done after the file has moved. The way it has been ...

  1. ajax form upload file
  2. ajax form upload image
  3. ajax form upload
  4. ajax form upload file mvc
  5. ajax form upload progress
  6. ajax upload form data
  7. ajax upload form php
  8. ajax form file upload php
  9. jquery ajax form upload
  10. jquery ajax form upload file
  11. ajax form submit upload file
  12. jquery ajax form upload image
  13. ajax beginform file upload
  14. ajax form serialize file upload
  15. ajax form data file upload
  16. ajax form submit image upload
  17. ajax form data image upload
  18. ajax form multiple file upload
  19. ajax form post file upload
  20. ajax file upload form using jquery

So, I have this string, which can contain a number of any length really. 10 100 1000 10000 100000 I need a regex which makes the strings like this: 10 100 1 000 10 000 100 000 For 100000, I have ...

So, I have this string, which can contain a number of any length really. 10 100 1000 10000 100000 I need a regex which makes the strings like this: 10 100 1 000 10 000 100 000 For 100000, I have ...

  1. javascript make regex from string
  2. javascript make regex
  3. javascript make regex case insensitive
  4. javascript make regex with variable
  5. js make regex from string
  6. js make regex

I am using Google code prettify on a page (working correctly), and I want to add a function which is called once this process completes. In the docs, they describe the following parameter: callback=...

I am using Google code prettify on a page (working correctly), and I want to add a function which is called once this process completes. In the docs, they describe the following parameter: callback=...

  1. using callbacks with promises
  2. using with callbacks
  3. using callbacks in javascript
  4. using callbacks in keras
  5. using callbacks in node js
  6. using callbacks in react
  7. using callbacks in java
  8. using callbacks in python
  9. using callbacks in c#
  10. using callbacks in js
  11. using callbacks in typescript
  12. using callbacks in swift
  13. using callbacks in express
  14. using callbacks in labview
  15. using callbacks in r
  16. using callbacks in class
  17. using callbacks in ros
  18. using function with callbacks