Hello I'm trying to create text boxes dynamically using for loop and want to implement calendar in all of them. my code is as follows:
for (var j = 1; j <= 5; j++) {
my_proj.innerHTML = my_proj.innerHTML +'<input type="text" name="txtStartDate" id="txtStartDate"+j runat="server" BackColor="#D6E4ED" BorderStyle="Inset" Width="10px" ></input>'
+'<a href="javascript:;" onclick="window.open(\'PopUp.aspx?textbox=txtStartDate+j\',\'cal\',\'width=250,height=225,left=270,top=180\')">'
}
As I need to have separate id for all the text boxes I tried to concat the variable j with it. But its not working and giving the error as 'Unknown identifier "startDate"+j"'
.
Please suggest something to solve this. Any other idea to work this out will also do. BTW I'm 开发者_如何学Pythontrying to implement it inside an .aspx page.
Thanks in advance.
Can anyone give me any other example to implement the same???? please.
You have to close the string before appending the variable to the string, so that it is recognized as a variable, and not just the letter 'j'.
So . . .
var j = 10,
str = "He is j years old";
. . . won't work; you need to do this:
var j = 10,
str = "He is " + j + " years old";
Your code should look like this:
my_proj.innerHTML = my_proj.innerHTML +'<input type="text" namea="txtStartDate" id="txtStartDate' + j +'" runat="server" BackColor="#D6E4ED" BorderStyle="Inset" Width="10px" ></input>'
+'<a href="javascript:;" onclick="window.open(\'PopUp.aspx?textbox=txtStartDate' + j + '\',\'cal\',\'width=250,height=225,left=270,top=180\')">'
You need to reformat your string so that it has the correct special character expressions. Double quotes and single quotes need to have a backslash so that the character is taken literally. There is also a large number of other Javascript special characters: http://www.w3schools.com/js/js_special_characters.asp
精彩评论