sahi: How to use the escape char in javascript

194 views Asked by At

In my app i will add row and update the fields next to it. eg. as below

1 User1namefield 
2 User2namefield 

for this first i need to identify label 1 and 2 and then i need to go and updated username field. Below code will work -

_setValue(_textbox("/UserName/",_near(_label("1"))),"userName1");
_setValue(_textbox("/UserName/",_near(_label("2"))),"userName2");

but i am writing function where i add multiple rows, and i need to generalize above code where it take $i (for loop).

How do I pass $i in "" quotes? I used below escape char but it is not working.

for(var $i=1; $i<=rows.length; $i++){
    _setValue(_textbox("/UserName/",_near(_label("\""+$i+"\"")))),"User1");
}
1

There are 1 answers

2
Lars Munkholm On

It looks to me like you have a parentheses too much.

Try with: _setValue(_textbox("/UserName/", _near(_label("\"" + $i + "\""))), "User1");

I'm not sure why you want to escape the quotation marks, though. If you want to convert the number to a string, this should do it:

_setValue(_textbox("/UserName/", _near(_label($i.toString()))), "User1");