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

document.getElementById('content').focus();

Why won't this work in Firefox:
document.getElementById('content').focus();
Is there something else to use?

Jul 23 '05 #1
6 15468
agf...@yahoo.ca wrote:
Why won't this work in Firefox:
document.getElementById('content').focus();
Is there something else to use?


What's the context in which you're using it? Is 'content' an id rather
than a name? Is this a form element?

Jul 23 '05 #2
ag****@yahoo.ca wrote:
Why won't this work in Firefox:
document.getElementById('content').focus();
Is there something else to use?


Advice above is good. If you are going to compare date strings, you
must compose them yourself.

var dtToday = Date()

will create a new date object with a date/time of the instant it was
created according to the settings of the user's local machine. This is
likely not accurate or reliable, so you must validate on the server.
Simply writing dtToday will create some string according to the
settings of the local machine, which could be anything.

Supposing txtDDate is the string "01/24/2005", then the equivalent date
string constructed from dtToday will be given by the script below.
Note that date & month less than "10" need a leading zero and that
getFullYear() is not supported on all browsers, so you may need to use
getYear and deal with it's eccentricities:
<script type="text/javascript">
function checkZero(a){
return (a < 10)? "0" + a : a;
}
function todayDate() {
var dtToday = new Date();
var dtTodayString = checkZero(+dtToday.getMonth()+1)
+ '/' + checkZero(dtToday.getDate())
+ '/' + dtToday.getFullYear();
alert(dtTodayString);
}
</script>
<button onclick="todayDate()">Click me</button>

In regard to date formats, if users' aren't going to see them (or
perhaps even if they are) the accepted international standard is
ISO8601. Your date above would become 2005-01-24 or 2005/01/24. Read
stuff on dates here:

<URL:http://www.merlyn.demon.co.uk/js-dates.htm>

The format mm/dd/yyyy is peculiar to the US and is likely to be
misinterpreted elsewhere in the world. ISO8601 dates should not be.

I appologise for baddly formatted code, but Google Groups insists on
removing all leading spaces, so there's not much I can do.

Jul 23 '05 #3
JRS: In article <11*********************@z14g2000cwz.googlegroups. com>,
dated Mon, 24 Jan 2005 17:45:19, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.au> posted :
ag****@yahoo.ca wrote:
Why won't this work in Firefox:
document.getElementById('content').focus();
Is there something else to use?
Advice above is good.


It does not look like advice; and your response appears unrelated.
If you are going to compare date strings, you
must compose them yourself.
That is not a requirement. It is, for example, perfectly correct to
compare for equality date strings in any fixed format; and to compare
for order date strings in an ISO 8601 format. User input validation can
easily ensure comparability.
var dtToday = Date()

will create a new date object with a date/time of the instant it was
created according to the settings of the user's local machine.
For me, it creates a string, according to typeof .
This is
likely not accurate or reliable, so you must validate on the server.
Simply writing dtToday will create some string according to the
settings of the local machine, which could be anything.
In my system, it is unambiguous; its value may be incorrect.
Supposing txtDDate is the string "01/24/2005", then the equivalent date
string constructed from dtToday will be given by the script below.
Note that date & month less than "10" need a leading zero and that
getFullYear() is not supported on all browsers, so you may need to use
getYear and deal with it's eccentricities:
Aha - a greengrocer !

getYear()%100 is reliable, so those who expect to lose interest before
AD2100 can often work with 2 year digits. I expect you have seen how
getFullYear can be emulated using getTime and any getYear such that
getYear()%100 is reliable.

function checkZero(a){
return (a < 10)? "0" + a : a;
}
Not a well-named function. Note that it assumes a non-negative integer
input, which is reasonable in this case. Also that it sometimes returns
a string and sometimes a number (assuming input is number); that is
usually harmless and harmless in this case - but if the intended format
were YYYYMMDD[*] then the results would be quite different for
day/month<10, as addition can occur.
[*] For YYYYMMDD, (getFullYear()*100+getMonth()+1)*100+getDate() is
better.

function todayDate() {
var dtToday = new Date();
var dtTodayString = checkZero(+dtToday.getMonth()+1)
First + is superfluous.
+ '/' + checkZero(dtToday.getDate())
+ '/' + dtToday.getFullYear();
alert(dtTodayString);
}
I appologise for baddly formatted code, but Google Groups insists on
removing all leading spaces, so there's not much I can do.


Don't use it, then. Example code NEEDS to be properly formatted. Find
a competently-designed news system. Even Developersdex is, IIRC,
better.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
No, not a form element...rather a DIV

<div id="" name="" contenteditable></div>

I need to be able to set focus on in order to paste into it...
IE is fine ... FF ... not so much.

Jul 23 '05 #5
ag****@yahoo.ca wrote:
No, not a form element...rather a DIV

<div id="" name="" contenteditable></div>

I need to be able to set focus on in order to paste into it...
IE is fine ... FF ... not so much.


Thats because FF does not support "contenteditable" and as such does not
support the concept of "focus" on it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
Any suggestions on how to get something like that to work in FF too?

Jul 23 '05 #7

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

Similar topics

1
by: Ben Rush | last post by:
I'm sure there is something out there for this, but I want to detect if document content has been changed for whatever reason. Say someone creates a javascript function which, say, changes some...
10
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
2
by: dotnetnoob | last post by:
hi all, i need to copy the content of a xml document and use it as xml element and insert into another xml document. Can someone tell me how? thank you
7
by: marty.overdear | last post by:
I am opening a new window using window.open. I need the new window to open on top of the parent everytime. I cannot use onBlur b/c the user will need to click back to the parent for information. ...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
5
by: dmk | last post by:
Hi All, function getWindowSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight =...
1
by: Morag | last post by:
I need to retrieve some data from an xml document using a web server, it's not working so I took out everything that was not necessary and put everything back line by line until I hit the problem, I...
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:
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...
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
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.