473,395 Members | 1,583 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.

onfocus, onblur on dynamic input box.

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 doesn't highlight. If I delete
the onblur line, each of the boxes is highlighted all the time
regardless of focusing the input box.

Can someone help me?

Tzachi
var addrownum=0;
function addRow(id){
var tbody = document.getElementById(id).getElementsByTagName(" TBODY")
[0];
var row = document.createElement("TR");
var td = new Array();
var y = 0;
addrownum++;
for (var y=1;3>=y;y++) {
td[y] = document.createElement("TD");
td[y].setAttribute("align","right");
S = document.createElement("input");
S.setAttribute("type","text");
S.setAttribute("name","c"+y+"r"+addrownum);
S.setAttribute("id","c"+y+"r"+addrownum);
S.setAttribute("dir","rtl");
S.setAttribute("class","box");
S.setAttribute("size","33%");
S.setAttribute("maxlength","33%");
// main problem

S.setAttribute("onFocus",S.className="box_on");
S.setAttribute("onBlur",S.className="box");
// end of main problem
td[y].appendChild(S);
row.appendChild(td[y]);
} // end of for loop
tbody.appendChild(row);
} // end of func
Jul 23 '05 #1
1 10456
On 19 Sep 2004 11:09:09 -0700, Tzachi <tz*********@hotmail.com> wrote:
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 doesn't highlight. If I delete
the onblur line, each of the boxes is highlighted all the time
regardless of focusing the input box.
[snip]
S.setAttribute("onFocus",S.className="box_on");
S.setAttribute("onBlur",S.className="box");


That because these lines don't do what you think they do. What actually
happens in the first line is that S.className is assigned the value,
'box_on'. S is then given the attribute, onFocus, with that same value. A
similar thing occurs with the second line.

Closer to what you want is:

S.setAttribute("onFocus", 'this.className="box_on";');
S.setAttribute("onBlur", 'this.className="box";');

however, it would be better to use the actual properties and assign
function references.

function blurInput() {this.className = 'box';}
function focusInput() {this.className = 'box_on';}

S.onblur = blurInput;
S.onfocus = focusInput;

In fact, you shouldn't be using setAttribute in the code you presented at
all unless this is an XML document. HTML elements define properties that
let you directly access the attribute value. For example,

S.type = 'text';
S.className = 'box';
// etc...

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

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

Similar topics

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...
3
by: the good guy | last post by:
For those who have been using Outlook Express, you must be pretty used to the fact that whenever you focus on the preview section, the header for the preview turns from grey to blue, while the text...
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...
1
by: Eric Trav | last post by:
Hello, I am using mozilla and javascript to change the style background color for my select with onfocus() and back to white with onblur(). When i process onfocus(); i have to click on the...
3
by: Nebulus | last post by:
Hey all. I'm working on some VERY big forms, and the user will easily lose their location if they get distracted - which happens a lot with the amount of phone traffic they get. Anyway, I have a...
1
kestrel
by: kestrel | last post by:
how do i add a javascript onfocus="this.class" type thing to my input form, to change the css class of the input?
1
by: clemtig | last post by:
Say I have a form with two input textfields. Each has an onFocus and onBlur. onFocus will unhide image #1. onBlur will hide image #1, show image #2 and validate the textfield. But the problem is that...
2
by: wolverine | last post by:
Hi All, In Mozilla Firefox, to onblur and onfocus event of each and every html element, the browser itself will attach a native event handler. I mean if you type,...
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
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
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
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
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.