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

Function not being called???

Status
Not open for further replies.

budapestnori

Technical User
Jan 15, 2004
33
HU
Here is the code I have. If I put nothing the onclick="enlarge()" event handler, the function enlarge is called. But the moment I try to put anything in there, esp. theimg[0], the enlarge function is not being called any longer. The only thing I could possibly see is that in the sting value of imghtml is this:

<a href=&quot;javascript:void(0)&quot; onclick=&quot;enlarge(&quot;images/gallery/w.jpg&quot;)&quot;;>
<img style=&quot;margin-top:57px;&quot; scr=&quot;images/gallery/w.jpg&quot; border=&quot;0&quot;></a>

Is there an issue with either the &quot; or / character?


function returnimgcode(theimg,mtop){
var imghtml=&quot;&quot;
var x=mtop

if (theimg[1]!=&quot;&quot;)
imghtml= '<a href=&quot;'+theimg[1]+'&quot; onclick=&quot;enlarge(&quot;'+theimg[0]+'&quot;)&quot;;>'
imghtml+='<img style=&quot;margin-top:'+x+'px;&quot; src=&quot;'+theimg[0]+'&quot; border=&quot;'+imgborderwidth+'&quot;>'
if (theimg[1]!=&quot;&quot;)
imghtml+='</a>'
return imghtml
}

function enlarge(img){
alert(img);
return;
}
 
Yes, you appear to have an issue with nested quotes (&quot;) - and a semicolon at the end of your &quot;onclick&quot; attribute.

Try:
Code:
<a href=&quot;javascript:void(0)&quot; onclick=&quot;enlarge('images/gallery/w.jpg');&quot;>

or

<a href=&quot;javascript:enlarge('images/gallery/w.jpg');&quot;>

When nesting quotes, you need to be very careful. One way is to escape them, or use their HTML equivalent when you output it in a script function.

Your &quot;returnimgcode&quot; function, appears to have nesting problems... try (cut/paste):
Code:
imghtml= &quot;<a href=\&quot;&quot;+theimg[1]+&quot;\&quot; onclick=\&quot;enlarge('&quot;+theimg[0]+&quot;');\&quot;>&quot;;

Hope this helps.

Pete.


Web Developer &amp; Aptrix / Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top