views:

88

answers:

5

I have the code

new_element.innerHTML ="<a href='#'><img src='"+imagePath+"' alt='' title='' width='466' onclick='addWidget('"+url+"');' height='165'></a>";

which will call the function addWidget:

function addWidget(url) {
  alert(url);
  var main= document.getElementById('mainwidget'); 
  main.innerHTML = "<iframe src='"+url+"' align='left' height='1060px' width='576px' scrolling='no'  frameborder='0' id='lodex'></iframe>";
} 

but it's not working. Any suggestions?

A: 

coding is correct, tell the error what are you getting.

Karthik
actually when i alert url in addWidget function its not alerting....
rajesh
Ok fine, i got your error let you try thisnew_element.innerHTML ="<a href='#'><img src='"+imagePath+"' alt='' title='' width='466' onclick=addWidget('"+url+"') height='165'></a>";
Karthik
thank u very much u all
rajesh
are you got correct answer?
Karthik
A: 

Since the iframe with it's src url is being dynamically set in client script, there is no GET being done against the dynamically generated url for the iframe.

Pierreten
A: 

First I agree with psd commend, you need to see whats the error messages on the console.

How ever I can not regist to say that you have warp the image with the link *a* handler, probably because you won to see the mouse icon to change over the image.

So its better to place the event on the link and not on the image:

   new_element.innerHTML =
  '<a href="#" onclick="return addWidget("' + url + '");"><img src="' + imagePath + '" ></a>';

Also note that I swap the " with ', and need the addWidget return false.

Aristos
A: 

Hi rajesh, try this

new_element.innerHTML ="<a href='#'><img src='"+imagePath+"' alt='' title='' width='466' onclick=addWidget('"+url+"') height='165'></a>";
Karthik
A: 
new_element.innerHTML ="<a href='#'><img src='"+imagePath+"' alt='' title='' width='466' onclick='addWidget("+url+");' height='165'></a>";
cosy