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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

correct format of string

Status
Not open for further replies.

project3

Technical User
Jan 10, 2008
22
US
I am trying to get the correct format of a string

a.innerHTML='<input type="text" name="o_item[]" value="">';

that works fine but i need to add a string in there

I thought it was like this

a.innerHTML='<input type="text" name="o_item[]" value="' + var + '">';

any help would be appreciated.
 
And theres another problem besides the [tt][maroon]var[/maroon][/tt] variable, the char-escaping.

project3 said:
[tt]a.innerHTML='<input type="text" name="o_item[]" value=[red]"[/red]' + var + '[red]"[/red]>';[/tt]

Any single doublequotes must be escaped.

Code:
var str = 'word"word'; [green]// Not correct[/green]
var str = 'word"word"word'; [green]// Correct[/green]

The proper code should be like:

Code:
a.innerHTML='<input type="text" name="o_item[]" value=[olive]\[/olive]"' + my_string + '[olive]\[/olive]">';


- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
No, Lowet, that part was fine. You only have to escape quotes when they're inside the same kind of quotes. Your examples are completely wrong, too.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top