473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically Assigning OnChange Handler

Hi All,

I'm creating textareas via the DOM and I'm trying to add the onchange
event to them. Here's my code:

mytextarea = document.createElement("textarea");
mytextarea.onchange = mymethod;
mytextarea.name = "textarea1";
mytextarea.value = "";
..
..
..

In another script file, I have the mymethod() function defined like
this:

function mymethod()
{
..
..
..
}
I tried various incarnations of setting the onchange event:

mytextarea.onchange = "mymethod()"; and onchange = "mymethod";. None
of which works. What's the secret to dynamically defining the
onchange event?
Jun 27 '08 #1
3 1725
On Jun 3, 2:08*pm, HugeBob <rnu...@gmail.comwrote:
Hi All,

I'm creating textareas via the DOM and I'm trying to add the onchange
event to them. *Here's my code:

mytextarea = document.createElement("textarea");
mytextarea.onchange = mymethod;
mytextarea.name = "textarea1";
mytextarea.value = "";
.
.
.

In another script file, I have the mymethod() function defined like
this:

function mymethod()
{
.
.
.

}

I tried various incarnations of setting the onchange event:

mytextarea.onchange = "mymethod()"; and onchange = "mymethod";. *None
of which works. *What's the secret to dynamically defining the
onchange event?
The following worked for me:

mytextarea.onchange = function() { mymethod(); };
Jun 27 '08 #2
On Jun 3, 2:36 pm, Tom Cole <tco...@gmail.comwrote:
On Jun 3, 2:08 pm, HugeBob <rnu...@gmail.comwrote:
Hi All,
I'm creating textareas via the DOM and I'm trying to add the onchange
event to them. Here's my code:
mytextarea = document.createElement("textarea");
mytextarea.onchange = mymethod;
mytextarea.name = "textarea1";
mytextarea.value = "";
.
.
.
In another script file, I have the mymethod() function defined like
this:
function mymethod()
{
.
.
.
}
I tried various incarnations of setting the onchange event:
mytextarea.onchange = "mymethod()"; and onchange = "mymethod";. None
of which works. What's the secret to dynamically defining the
onchange event?

The following worked for me:

mytextarea.onchange = function() { mymethod(); };
Hi Tom,

That worked! Thanks.
Jun 27 '08 #3
The following worked for me:
>
mytextarea.onchange = function() { mymethod(); };
This should also work

mytextarea.onchange = mymethod
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Aaron C | last post by:
This is kindof a newbie question, so please bear with me... I need to pass the selected option of a <select> tag into a query string, so that the page is reloaded with the selected option already...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
2
by: Steve Caliendo | last post by:
Hi, I am dynamically generating check boxes in the Panel control based on a database field, and I've set the AutoPostBack property to True. How can I determine which CheckBox caused the post...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
5
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup',...
1
by: bambr | last post by:
I'm using following code: function cloneRow(tBodyId, sourceRowId) { var obj = document.getElementById(tBodyId); if(obj.tagName != 'TBODY') { for(var i = 0; i < obj.childNodes.length;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.