Problem with ["] and ['] in javascript string

This is a discussion on "Problem with ["] and ['] in javascript string" within the JavaScript Forum section. This forum, and the thread "Problem with ["] and ['] in javascript string are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 12th, 2007, 16:58
New Member
Join Date: Sep 2007
Location: Singapore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Problem with ["] and ['] in javascript string

Hi all,

I encounter a problem in dealing with " and ' in javascripts.

The case is that I have to create an image tag with onclick trigger another javascript function which take in param as below:

document.<sth>.innerHTML = "<img scr='img/somthing.gif' onclick='imageClicked('sample1')'";

But it failed to function even when I tried to use &quot and VAR in splitting the variable...

really need help from yrs...
thanks much !!
Reply With Quote

  #2 (permalink)  
Old Sep 12th, 2007, 17:05
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: Problem with ["] and ['] in javascript string

You have to escape some of the quotes. I'd do it like this:

Code: Select all
 document.<sth>.innerHTML = '<img scr="img/somthing.gif" onclick="imageClicked(\'sample1\')"';
That should work.
Reply With Quote
  #3 (permalink)  
Old Sep 13th, 2007, 02:52
New Member
Join Date: Sep 2007
Location: Singapore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem with ["] and ['] in javascript string

Thanks c010depunkk!! It's solved
Reply With Quote
  #4 (permalink)  
Old Sep 13th, 2007, 06:20
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: Problem with ["] and ['] in javascript string

no problem....
Reply With Quote
Reply

Tags
innerhtml, string

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Decoding a string in Javascript omega113 JavaScript Forum 1 Jun 12th, 2008 16:07
Javascript problem - unterminated string jitumandalia JavaScript Forum 2 Feb 14th, 2008 07:43
Appending "..." after so many pixels in a string RooZ Web Page Design 7 Jan 24th, 2008 17:00
[SOLVED] Javascript Printer-Friendly Page &quot;Creator&quot; Stuart JavaScript Forum 33 Oct 13th, 2007 13:06
<option value="yes" class="x"> problem in Firefox mameha1977 Web Page Design 1 Jun 21st, 2006 11:20


All times are GMT. The time now is 05:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43