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

element focusing

how can you set a Global variable and set it to Y when a text field has
focus and N when the text field does not have focus and then depending
on the value preforms a task inside a function (for when a form is
submited)

Jun 2 '06 #1
5 1254
Jordan Pittman said the following on 6/1/2006 10:35 PM:
how can you set a Global variable and set it to Y when a text field has
focus and N when the text field does not have focus and then depending
on the value preforms a task inside a function (for when a form is
submited)


onfocus="var globalVariable = 'Y'"
onblur="var globalVariable = 'N'"

That was tough.

Y and N are bad choices though.

onfocus="var hasFocus = true"
onblur="var hasFocus = false"

if (hasFocus)

But it may or may not do what you think/want it to do.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 2 '06 #2

Randy Webb wrote:
Jordan Pittman said the following on 6/1/2006 10:35 PM:
how can you set a Global variable and set it to Y when a text field has
focus and N when the text field does not have focus and then depending
on the value preforms a task inside a function (for when a form is
submited)

onfocus="var hasFocus = true"
onblur="var hasFocus = false"

if (hasFocus)


If you use var, it does not create a global variable. In any case the
idea is flawed because clicking submit will usually blur the other
elements. The best you can hope to achieve is to record a focus event,
for whatever use that may have.

Jun 3 '06 #3
VK
Stephen Chalmers wrote:
If you use var, it does not create a global variable.


I would expand this note a bit otherwise it may sound like the keyword
"var" by itself doesn't allow to create global variables.

"var" used /within a function/ creates local variable, without "var"
global variable. The fact that many forgets is that intrinsic event
hadlers are anonymous function, so
...onfocus="var Foo='Bar';">
really is
function anonymous(event) {
var Foo='Bar';
}
When present with its "real face" it is obvious that indeed using "var"
within intrinsic event handlers creates local variables for the given
anonymous function.

One have to use it without "var":

...onfocus="Foo='Bar';">
(now Foo is global)

This is a simplified case w/o extra check for IE's issue, so one will
get a script error if the current page contains an element with ID
"Foo".

Jun 3 '06 #4
well i have no need for this now, i went an entire different approach
after i realised how to do it, thanks anyway and you never know this
may help some one else

Jun 4 '06 #5
Jordan Pittman wrote on 04 jun 2006 in comp.lang.javascript:
well i have no need for this now, i went an entire different approach
after i realised how to do it, thanks anyway and you never know this
may help some one else


Need for what?

Please quote what you are replying to. If you want to post a followup via
groups.google.com, don't use the "Reply" link at the bottom of the article.
Click on "show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
<http://www.safalra.com/special/googlegroupsreply/>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 4 '06 #6

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

Similar topics

1
by: Igor | last post by:
Is there any way to resort and xml document using xslt based on element position. For example if I have xml like this: <root> <element> 1st thing </element> <element> 2nd thing </element>...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
3
by: Steven | last post by:
I have a question about the focusing on windows form control. First of all, I have a main windows form (MainFrm) for my application, another form (NewFrm) will be displayed if pressing one of the...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
2
by: Ming | last post by:
I am thinking to start a business focusing on PHP, i.e.: to develop modules for popular open source php applications, like drupal, wordpress, joomla, etc. Any suggestion on how to make it a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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?
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,...

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.