0

I am having problem passing value to a function called inside onblur event of handlebar template.

<div class="property" id="property">
  <span class="innertitle">Property/Site Details</span></br>
  <table id="propDetails" width="400" border="0">{{#dispycolumns}}
     <tr>
        <td>{{FieldLabel}}</td>
        <td>
          <input name="{{fieldName}}" type="text" value="{{FieldValue}}" maxlength="100" onblur="validateFields(this.value,this.name,{{FieldLabel}});" />
        </td>
     </tr>{{/dispycolumns}}
  </table></br></br>
</div></br></br>
<input style="font-size:12px;float:right;margin-top: -19px;margin-left: 59px;background-color:#0099FF;" type="button" name="Next" value="Next" onclick="savePropertyDetails();loadConsumptionData()" />

In above code i am calling validateFields() function with 3 arguments.I have a problem passing the third argument {{FieldLabel}}. I need single quotes around it to properly compile. Request help in doing it.

SOFuser123
  • 95
  • 3
  • 11

1 Answers1

1

You must wrap quotation marks around {{FieldLabel}} where it is intended to be a string literal argument:

onblur="validateFields(this.value, this.name, '{{FieldLabel}}');"
76484
  • 8,498
  • 3
  • 19
  • 30
  • Sorry to say that it is not working. I get syntax error.If i use just {{FieldLabel}} also function is not called due to syntax error.This is because whole of the above html is rendered using handlebars,so i have declared a variable like var teplate_src="
    "; This is why i think quotes mismatch is happening.
    – SOFuser123 Mar 27 '14 at 11:14
  • If you are creating your template source as a string then you will certainly need to escape the quotes within it using a backslash, [\]: var template_src="
    ";
    – 76484 Mar 27 '14 at 15:39
  • Thanks it worked. I had tried escapinng before but it had not worked..Dont know what had gone wrong. – SOFuser123 Mar 28 '14 at 10:05