Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
changes function dynamically
Old 09-07-2007, 03:46 AM changes function dynamically
Novice Talker

Posts: 13
Name: Ham
Location: Singapore
Trades: 0
Hi, i would like to add buttons, each with a different onclick function. I have 2 version of code, one of them workin in firefox while the other is not working at all:

the one working in firefox:
Code:
function addButton(aid, bit, value, onclick) {
 var tmp = "<INPUT TYPE=button NAME='"+bit+"' ID='"+bit+"' onCLICK="+onclick+">";
 parent.document.getElementById(aid).innerHTML += tmp;
}
the one not working at all:
Code:
function addButton(aid, bit, value, onclick) {
 var tmp = document.createElement("input");
 tmp.name = bit;
 tmp.id = bit;
 tmp.type = 'button';
 tmp.value = value;
 tmp.onclick = function() { onclick };
 gE(aid).appendChild(tmp);
}
-aid is the id of the element that the button is going to be added to.
-bit is the name and id of the new button
-value is the value of the button
-onclick is a string that is suppose to be the function to be executed when the new button is clicked.


e.g. :
addButton('form1', 'button1', 'Alert me', "alert('You are alerted')";
addButton('form1', 'button1', 'Get value', "document.getElementById('textbox1').value='newval ue'");


Thanks in advance!
__________________
HAFIOŠ Networks -
Please login or register to view this content. Registration is FREE

Exclusive webhosting services
hafio is offline
Reply With Quote
View Public Profile Visit hafio's homepage!
 
 
Register now for full access!
Old 09-07-2007, 09:39 AM Re: changes function dynamically
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by hafio View Post
the other is not working at all:
Do you mean that the element doesn't appear or that it doesn't do anything?

If it's the latter, try:

Code:
 tmp.onclick = new Function( onclick );
logic ali is offline
Reply With Quote
View Public Profile
 
Old 09-08-2007, 12:08 AM Re: changes function dynamically
Novice Talker

Posts: 13
Name: Ham
Location: Singapore
Trades: 0
Thanks alot, it worked
__________________
HAFIOŠ Networks -
Please login or register to view this content. Registration is FREE

Exclusive webhosting services
hafio is offline
Reply With Quote
View Public Profile Visit hafio's homepage!
 
Old 09-08-2007, 01:23 AM Re: changes function dynamically
Novice Talker

Posts: 13
Name: Ham
Location: Singapore
Trades: 0
sorry, is there a way to remove that element if i want to?


sorry, nvm, got it. thanks
__________________
HAFIOŠ Networks -
Please login or register to view this content. Registration is FREE

Exclusive webhosting services

Last edited by hafio; 09-08-2007 at 01:26 AM..
hafio is offline
Reply With Quote
View Public Profile Visit hafio's homepage!
 
Reply     « Reply to changes function dynamically
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47191 seconds with 12 queries