Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating String in Javascript 1

Status
Not open for further replies.

lbrooks

IS-IT--Management
Jan 20, 2004
42
US
I have the following string:

myfunction = "'insertbb('" + myvalue + "')'"
sNewRecipe = "<table>tr><td class='stySubItem1'>input type='button' onClick=" + myfunction + " value='Browse'/> </td></tr></table>"
folderTree.innerHTML = sNewRecipe

With the above I get a syntax error
If I remove the single quote from myfuntion as such:

myfunction = "insertbb('" + myvalue + "')"
sNewRecipe = "<table>tr><td class='stySubItem1'>input type='button' onClick=" + myfunction + " value='Browse'/> </td></tr></table>"
folderTree.innerHTML = sNewRecipe

With the above I get I get an Expect ")" error.

I am using javascript.

I do not understand why I am getting the syntax errors. Any help would be appreciated. I could be over looking something, but since I can't seem to figure it out, I thought I would ask for help. Thanks in advance.

 
try making the following changes, if it doesn't work then I'm guessing you have a problem with what's in the myvalue variable:
Code:
myfunction = "'insertbb([!]\"[/!]" + myvalue + "[!]\"[/!])'"[!];[/!]
sNewRecipe = "<table>[!]<[/!]tr><td class='stySubItem1'>[!]<[/!]input type='button' onClick=" + myfunction + " value='Browse'/> </td></tr></table>"[!];[/!]
folderTree.innerHTML = sNewRecipe[!];[/!]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Oh Wow thanks kaht! the "<" was not the problem, as I had stripped out part of a larger string it to post it. But adding the \" worked. Thanks again.
 
Glad I could help, thanks for the star [thumbsup2]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top