• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

adding Onclick event to a button object

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
What i did was this but the onclick event is not adding to the button object. I could see the button being added to the document but if i click it there is no reaction. can anyone solve this problem

function init() {
var but = addInput("but", "click", "button");
but.onClicck ="showImage";
document.getElementById("main").appendChild(but);
}

function showImage() {
var img = addInput("im", "", "img");
img.src = "c:/veshnu/tata-logo.gif";
document.getElementById("main").apendChild(img);
}

function addInput(name, value, type) {
var hid = document.createEllement("input");
hid.type = type;
hid.name = name;
hid.value = value;
return hid;
}
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how about
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it can be done multiple ways.

but.onclick = showImage;
or
but.onclick = function(){showImage();};
or
but.onclick = new Function("showImage();");

Eric
 
reply
    Bookmark Topic Watch Topic
  • New Topic