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

Dynamic CreateElement add onblur?

Hello javascript coders :( ,I am trying
to add an [b:be2ca59534]onblur[/b:be2ca59534] event to my code.
This is where I dynamically create a textfield.I want to assign it an
[b:be2ca59534]onblur[/b:be2ca59534] event handler like so.How do I
add a event to a newly created option text field.Thanks :D

for( ;k < holdHalfHours; k++ ){
timeLog.appendChild(br);
l = k +1;

var newHoldDesc = document.createTextNode( "Hold
Half Hour" + l );

timeLog.appendChild( newHoldDesc );
var inputHoldText =
document.createElement("input");

inputHoldText.type = "text";
inputHoldText.size = "5";
inputHoldText.id = "txtfHolding" + l;
inputHoldText.onblur = "checkValue(this);";
timeLog.appendChild(inputHoldText);

timeLog.appendChild( newSpacer
);

Developers Forum - @ DevPlug.com
Jul 23 '05 #1
2 11338
Ovi
I have a nice example which might help you outthere, here goes...

###############################Start

<html>
<head>

<script>
function newInput(name, prevId) {
var id = 1 + prevId;
var newDiv = document.createElement('div');
var newInput = document.createElement('input');
newInput.name = name;
newInput.id = id;
newDiv.appendChild(newInput);
document.getElementById('inputList').appendChild(n ewDiv);
newInput.focus();
load();
}
function move(element, distance) {
var parent = element.parentElement;
var index = 0;
for (var i = 0; i < parent.children.length; i++) {
if (parent.children[i] == element) {
index = i;
}
}
if (element.value != '') {
if (index == parent.children.length - 1) {
if (distance > 0) {
return true;
} else {
newInput(element.name, element.id);
}
}
if (parent.children[index + distance].value != '' && index + distance >
0) {
parent.removeChild(element);
parent.insertBefore(element, parent.children[index + distance]);
parent.children[index + distance].focus();
}
}
}
function keyPressed(e) {
if (!e) {
e = window.event;
var target = e.srcElement;
var key = e.keyCode;
} else {
var target = e.target;
var key = e.which;
}
var div = target.parentElement;
if (key == 38) {
move(div, -1);
} else if (key == 40) {
move(div, 1);
}
return true;
}
function lostFocus(e) {
if (!e) {
e = window.event;
var target = e.srcElement;
} else {
var target = e.target;
}
if (target.type == 'text') {
var id = 0;
var inputs = document.getElementsByTagName('input');
if (inputs[inputs.length - 1] == target) {
if (target.value.length > 0) {
newInput(target.name, target.id);
}
} else {
if (target.value.length == 0) {
document.getElementById('inputList').removeChild(t arget.parentElement)
}
}
}
return true;
}
function load() {
var x = document.forms[0].elements;
for (var i=0;i<x.length;i++) {
x[i].onblur = function (e) {lostFocus(e)};
x[i].onkeyup = function (e) {keyPressed(e)};
}
}
</script>

</head>
<body onload="newInput('test', 0); load();">
<form name="whatever" ID="Form1">
<input type="submit" value="Save" NAME="submit" ID="Submit1">
<div id="inputList">
</div>
</form>
</body>
</html>

###############################End


andyalean wrote:
Hello javascript coders :( ,I am trying
to add an [b:be2ca59534]onblur[/b:be2ca59534] event to my code.
This is where I dynamically create a textfield.I want to assign it an
[b:be2ca59534]onblur[/b:be2ca59534] event handler like so.How do I
add a event to a newly created option text field.Thanks :D

for( ;k < holdHalfHours; k++ ){
timeLog.appendChild(br);
l = k +1;

var newHoldDesc = document.createTextNode( "Hold
Half Hour" + l );

timeLog.appendChild( newHoldDesc );
var inputHoldText =
document.createElement("input");

inputHoldText.type = "text";
inputHoldText.size = "5";
inputHoldText.id = "txtfHolding" + l;
inputHoldText.onblur = "checkValue(this);";
timeLog.appendChild(inputHoldText);

timeLog.appendChild( newSpacer
);

Developers Forum - @ DevPlug.com


Jul 23 '05 #2
andyalean wrote:
Hello javascript coders :( ,I am trying
to add an [b:be2ca59534]onblur[/b:be2ca59534] event to my code.
This is where I dynamically create a textfield.I want to assign it an
[b:be2ca59534]onblur[/b:be2ca59534] event handler like so.How do I
add a event to a newly created option text field.Thanks :D
When posting code, do not use tabs. Replace them with two or four
spaces and manually wrap code at about 70 character to allow a couple
of re-posts without automatic wrapping.

for( ;k < holdHalfHours; k++ ){
timeLog.appendChild(br);
l = k +1;

var newHoldDesc = document.createTextNode( "Hold
Half Hour" + l );

timeLog.appendChild( newHoldDesc );
var inputHoldText =
document.createElement("input");

inputHoldText.type = "text";
inputHoldText.size = "5";
Creating inputs using DOM methods can be problematic in some
browsers, test thoroughly.
inputHoldText.id = "txtfHolding" + l;
inputHoldText.onblur = "checkValue(this);";


Guessing that 'chekValue()' is a function defined elsewhere, then:

inputHoldText.onblur = function () {checkValue(this)};

should do the trick.

[...]

--
Rob
Jul 23 '05 #3

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

Similar topics

1
by: Cindy | last post by:
hi, Can someone point me to a website where I can find a "create dynamic rows" javascript that work for IE, NS6 & NS7? Thank You. regards, Cindy
7
by: Cindy | last post by:
"kaeli" <infinite.possibilities@NOSPAMatt.net> wrote in message news:MPG.197482677bbc284b989702@nntp.lucent.com... > In article <bed8e3$m6r$1@mawar.singnet.com.sg>, stayhardsg@yahoo.com.sg >...
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...
2
by: The_Original_MB | last post by:
I have a task to create tables dynamically, using the javascript DOM. The current method uses a 1px x 1px IFRAME to loop through some data generation stuff, and then call JS functions in the parent...
5
by: pizzy | last post by:
I am having a problem with the last results. I can't seem to be able to get the input2A and input3A to appear. I don't seem to have a problem with the show and hide after a number is entered and...
1
by: rubenhan | last post by:
Hi guys, I'm a javascript beginner and I am trying to write this simple javascript code that will add text field when I type some texts in the preexisting text field. When the text field is...
1
by: aashishn86 | last post by:
i create dynamic rows using this function : function addRow() { var tbl = document.getElementById('applications'); var lastRow = tbl.rows.length; var iteration = lastRow; var row =...
2
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.