0

What I need to do, is to set the property name dynamically. I will show you the code I am trying:

 for (i = 0; i < $nrOfCriteriiReducere; i++)
  {

       var eroareText = "eroareIDCazReducere" + " "  + i;
       var eroareHtmlClass = ".eroareCazReducere" + i;


        if (raspuns.eroriProprietar.eroareText)
         {
             $(eroareHtmlClass).css("display", "inline");
             $(eroareHtmlClass).text(raspuns.eroriProprietar.eroareText);
          }
    }

It is not working, and it is giving me the:

Uncaught SyntaxError: Unexpected string error.

How can I achieve this?

Solution:

Here is the solution (I also changed it by setting the name attribute dynamically, and not the class):

for (i = 0; i < $nrOfCriteriiReducere; i++)
{

       var eroareText = "eroareIDCazReducere" + " " + i;
       var eroareName = "eroareCazReducere" + i;

       if (raspuns.eroriProprietar[eroareText])
       {

             var name = "[name=" + eroareName + "]";
             $(name).css("display", "inline");
             $(name).text(raspuns.eroriProprietar[eroareText]);
       }
 }
Alina
  • 142
  • 2
  • 13
  • are you sure you have css classes with numbers? (.eroareCazReducere1, .eroareCazReducere2, .eroareCazReducere3, etc) ? – Dory Zidon Jun 16 '15 at 12:04
  • `eroareText` != `raspuns.eroriProprietar.eroareText`, you are not using `eroareText` in your code. For the syntax error, can't see it in this piece of code – Hacketo Jun 16 '15 at 12:05
  • You are right, I should add the classes names as the name attribute of the span, in order to identify it. – Alina Jun 16 '15 at 12:06
  • eroareText is the parameter name, while raspuns.eroriProprietar.eroareText should return the parameter value – Alina Jun 16 '15 at 12:07
  • Quentin, thank you for pointing me to the solution. I guess I did not searched well :). – Alina Jun 16 '15 at 12:11

0 Answers0