473,395 Members | 1,556 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,395 software developers and data experts.

How to call a js function on dynamically created input?

1
I am trying to call a js function on blur effect of dynamically created textbox. Code are as follows.

js to add dynamic text box
Expand|Select|Wrap|Line Numbers
  1. {
  2. var el3 = document.createElement('input');                    
  3.     el3.type = 'text';                                    
  4.     el3.name = 'children' + i;                                
  5.     el3.id = 'children' + i;                                    
  6.  
  7.     //el3.setAttribute('onblur',"myFunction()");
  8.     el3.onblur = function(){myFunction();};
  9.     thirdCell.appendChild(el3);                        
  10.     frm.h.value=i;                                        
  11.     i++;    
  12.  
  13. }
JS Function to be called on blur effect of above dynamically created element.

Expand|Select|Wrap|Line Numbers
  1. function myFunction()
  2. {
  3. var x = document.getElementById("child1").value;
  4. for(i=0;i<x;i++)
  5. {
  6.     var childAge =  prompt("Enter Child " + (i+1) + " age")
  7.     childageDetail.push(childAge);
  8.  
  9. }
  10. //Loop for child age display
  11. for(ageDisplay = 1; ageDisplay < childageDetail.length; ageDisplay++)
  12. {
  13.     alert("Child "+ ageDisplay +" age "+ childageDetail[ageDisplay]);
  14. }
  15.  
  16. }
Dec 22 '14 #1
1 1974
Dormilich
8,658 Expert Mod 8TB
1)
Expand|Select|Wrap|Line Numbers
  1. el3.onblur = function(){myFunction();};
can be simplified to
Expand|Select|Wrap|Line Numbers
  1. el3.onblur = myFunction;
2) I’m not entirely sure what your problem is.
Dec 22 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Thomas | last post by:
Hi, I'm having a problem with the dynamically created inputfields in Internet Explorer. The situation is the following: - I have a dynamically created table with a textbox in each Cell. - It...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
1
by: theJonster | last post by:
Hi, I have created a page with a list of items and next to these items are comment boxes and check boxes which were dynamically created like this: check = new CheckBox();...
2
by: Ed Jay | last post by:
I'm dynamically creating several form input elements: mValue = integer constant; for(var j = 0; j < mValue; j++) { target = "imgCn"+ j; eName = "myFile"; eName = eName+jj;...
1
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function ////////////////////////////////////////////////////////////////////////////////////...
1
by: Appu2008 | last post by:
Hi, Iam trying to invoke a javascript calendar in the click event of an input box. The input box is an array created dynamically. But the clicking does not works correct. I think the problem...
12
by: mitchell | last post by:
hi, i am having problems while uploading a file. i created an input element of file type and appended it to a form. after selecting the file when i click on submit the form becomes blank and i...
4
Claus Mygind
by: Claus Mygind | last post by:
I understand how to link an element that exists on the form with a prototype function or class. But how do I link/bind a dynamically created element with the same prototype function or class In...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.