473,405 Members | 2,287 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,405 software developers and data experts.

to add onblur function to an appended Input element

Hey, guys.

My basic idea is this. When I write "1" in the pre-existing text field and onblur, I want to add a new field with a set of attributes, which turned out to be the same as the pre existing text field. (I don't want to use clonenode because of the compatibility issue)

So I want that new text field to behave like the old text field. However, the new text field does not create another text field when I write "1" into it and onblur it. Is "node.onblur = function" not a right syntax when I'm assigning attribute?

In essence I want my new text field have this html code behind it.
[HTML]<input type="text" onblur="addform(i)" name="copy[]"/>[/HTML]

I'm using i to designate the position of name "copy[]" array.

The first text field works fine. It creates a new text field but it looks like it's not adding the onblur attribute as I checked with Firebug. What am I doing wrong?

One more question. Every time a new field is created, it is created right below the original text field. If I want to append that text field to the right of the original text field, how do I pull this off?

Thank you

Expand|Select|Wrap|Line Numbers
  1. var textInput;
  2. var inHere;
  3. var i=0;
  4. var newForm;
  5. function addform(i) {
  6.  
  7.  
  8.     textInput = document.getElementsByName("copy[]")[i];
  9.     i++;
  10.     if (textInput.value == "1") { // if text field's value is 1 then create another text field with the following attribute.
  11.         newForm = document.createElement("input");
  12.         newForm.type = "text";
  13.         newForm.name = "copy[]";
  14.         newForm.onblur = "addform(i)";
  15.         inHere = document.getElementById("inhere");
  16.         inHere.appendChild(newForm);
  17.        } else document.write("failed");
  18.  
  19. }
[HTML]
<div id="add" >
<form action="addform.php" method="post" name="addformtest" >
<input type="text" onblur="addform(i)" name="copy[]"/>
<div id="inhere"> </div>
</form>
</div>
[/HTML]
Dec 11 '08 #1
4 6898
acoder
16,027 Expert Mod 8TB
Change
Expand|Select|Wrap|Line Numbers
  1. newForm.onblur = "addform(i)";
to
Expand|Select|Wrap|Line Numbers
  1. newForm.onblur = function() {addform(i););
To append to the right of the text box, use a combination of insertBefore and nextSibling to simulate insertAfter.
Dec 11 '08 #2
rnd me
427 Expert 256MB
specifically:

inHere.parentElement.insertBefore(newForm, inHere.nextSibling )
Dec 11 '08 #3
thank you guys. all solved.
Dec 13 '08 #4
acoder
16,027 Expert Mod 8TB
You're welcome. Post again if you have any more questions.
Dec 13 '08 #5

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

Similar topics

10
by: CES | last post by:
All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon...
1
by: Rich Morey | last post by:
Hello, I have created a form and assigned each of the form elements to a class in a style sheet. I would like to know if it is possible to add 'OnFocus' and 'OnBlur' events to the style sheet...
1
by: Tzachi | last post by:
Hello all, I have a function that dynamically adds rows and columns to the page. Everything works well except onfocus // onblur attributes. For some reason, when entering the input box it...
1
by: Christoph | last post by:
I'm trying to validate some HTML form elements when the user tabs out of each element. However, I'm having some problems. It appears that the order of events is onChange followed some time...
2
by: D. Alvarado | last post by:
Hi, I'm having some trouble with the "onBlur" event in the BODY tag. Ideally, what I want to happen is that when someone leaves window A, window A executes a command. I had put <body...
2
by: andyalean | last post by:
Hello javascript coders :( ,I am trying to add an onblur event to my code. This is where I dynamically create a textfield.I want to assign it an onblur event handler like so.How do I add a event...
2
by: John Kotuby | last post by:
Hi all, I am integrating some 3rd party grids into a large ASPX form page in VS 2008 using VB. I have 4 different grids on the page. The object is to not allow the user to leave a grid if...
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
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
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
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...

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.