I would to change the color of some td cells if there is text in it. Right now this code does the job, but it changes the color of evry table. I'd like to know a way to do this on one table in my page and not all of them.
var count='0';
var TDs=document.getElementsByTagName('td')
var length=TDs.length;
i='0';
I am doing some work, where I want to have a table heading that remains in a fixed position, when the window is scrolled (I will ultimately have a very long table). I have written the code below, which fixes the heading.
I am trying to make it so that each body row of the table gets hidden, when the window is scrolled such that the row passes above the heading row.
To do this I need to somehow detect the distance of each row from the top of the window as the window is scrolled so I can detect when it goes above the fixed heading row. I have tried to do this using offsetTop and scrollTop in the code below, but it doesn't seem to be working (in Safari at least, which I am using for my main testing).
Does anyone know a simple way of detecting the distance to the top of the window so I can use it in my code below, which will work in all browsers?
(I don't really want to use div, and overflow-y:auto to achieve the fixed heading scrollable table, because I don't want to have a sub-section with its own scrollbar. I just want to have the main page scrollbar when the list gets long enough to require it.)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head>
I'm trying to use JS to move the cursor from my user login text field to the password text field - I've put the onKeyPress() event in the user input tag but then I press the Tab key the cursor doesn't move -
function detect_tab_key() { var key_code = window.event.keyCode; if (key_code == 9) { document.forms[0].frm_password.focus(); document.forms[0].frm_password.select(); } }
Why is it that you need the return keyword? Where does the argument event come from?
I know it works, I just want to know why it works.
I've been looking at some refferences and can't seem to find an answer if someone could give me an explanation or point me to a website, that would be great.
I am trying to do something I thought would be simple in javascript, and I'm at a loss. First code is GOOD code, except that it does not account for the possibility that the button(s) in question do NOT exist. The second and third subsets are two of several attempts to do just that. Code:
I need to write a script that detects if a person has flash installed and if they do then do something, if not do something else.
I can do this no problem with javascript - except for the detecting flash part. I have no idea how to have a js detect flash - or even if its possible.
If I detect an empty textbox, I fill it with a value ('Dad'). If I do this twice, the second time around IE 6 fails to notice that I've cleared the textbox again, thus leaving the textbox cleared. Is there a recommended workaround? Opera 7.23 is detecting the second deletion fine.
I am trying to detect whether a user entered text in a textarea or hit the delete/backspace button (thus, erasing something). Once that is detected, I would like to set "var bSaveRequired = true;". It would be great if this function worked cross-browser -- IE 6.0 and Firefox.
Say I'm on the site www.xyz.com and on a certain page if the user leaves the domain xyz.com, I have a popup cme up w/ stuff. I don't need to know what the new domain is, I just want to know if the user left / is leaving xyz.com.
I'm trying to determine if the user clicks the stop button during a post send, basically. Specifically, if a user is uploading a file to my server, and they click stop at some point, I need to be able to tell the server that stop was clicked, so it doesn't think that's the whole file. I've noticed that an error message is written to the Apache log, but that seems like a strange way to keep track of user-interrupted events. (Note: this is Apache/mod_perl server-side)
I guess what I'm thinking now is that JavaScript detects the stop (since it is client-side), then sends a message to the server that an error occurred, or something. Like I said, the onstop event is not doing what I'm expecting, and Firefox doesn't like it anyway, not to metion the other browsers out there. So my question is what's the "idiom" or "standard way" of detecting this sort of situation. I'm quite certain I'm not the first one to need it.
If I want to detect a user's language, so that I can change some text to suit them, how do I do that in Javascript?
Or aren't modern browsers supposed to be able to cope with more than one language on a page, separated somehow by language identifiers, and display only the appropriate text? Maybe I was dreaming when I read that.
I'd like to be able to detect when page content is dynamically changed by Javascript. I'd like to detect any changes to the content, such as the addition of new DOM elements and when DOM elements that are hidden are made visible (or vice versa). I will have no advance knowledge of the scripts that will be run along with the script I will create.
I've implemented a solution that works reasonably well, but I'm not sure if there are cases I'm not thinking of where it will fail, or if there are more efficient means of doing the same thing.
My solution is to simply retrieve and periodically compare the content of the innerHTML property of the main body tag elemnt.
So, summarized as follows:
function check() { var bodyContent = document.getElementsByTagName('body')[0]; if(bodyContent != oldBodyContent) { alert('body changed'); } setTimeout(check, 500); }
I am writing a script that uses xmlhttp.open, when i attempt to open a protected page I get the login prompt for my htpasswd. Is it possible to detect if there is a login requirement before the login prompt and if there is a login just do something else? I can use xmlhttp.status and check for 200 but if I do this then it would happen after the login prompt.
I'm making an Intranet site for someone who is not very familiar wit making websites, thus I would like to make it as simple as possible fo her when she needs to update it.
The intranet site uses frames - one menu frame that is always present and one frame into which the content is loaded. The intranet sit features many, many links to both internal and external pages - i internal pages within the intranet and external pages on the interne (http://)
What I would like to do is make it so that if a link is internal, th content will load into the content frame and the menu frame will remai at the side, but if the link is external, it will load the target int the entire browser window. Using HTML, this would simply be a matter o stating the href and then target="content_frame" for internal pages o target="_top" for external pages.
But, like I said, I am making this site for someone who is not familia with linking targets and even if I told her to define the targe whenever she makes a link, she'd probably forget or get confused an then wonder why external pages are loading with the intranet menu fram still present or why intranet pages are loading with no menu at th side!
While I have good experience with HTML, I am fairly new to JavaScript which is why I am here asking for help.
I understand that Javascript can detect the protocol of a link, believe you would use "link.protocol". In basic terms, what I woul like to do is:
if link.protocol = "http://" then target="_top" els target="content_frame"
But since I'm not familiar with the precise way of coding JavaScript, would just like some help with transforming this into correc JavaScript code so that it will work.
I've written a script that displays tooltips when your mouse hovers over a link - all this is fine, but when I click on the link and move to another page, then click the back button on the browser to go back, the tooltip for the link I clicked is still visible! It'd be great if there was a way of detecting the button had been pressed so that I can hide it...
p.s. I tried onclick = "tooltips.hideToolTip(4); return true;" for the links but no joy...
I am trying to detect the parent URL on a page for a Facebook application so that if the user is on my site rather than accessing the application via Facebook they will be redirected to the FB App page.
In PHP I can use: if(strstr($parenturl,"mysite.com")){header("location:fbapp.com");exit;}
Is it possible to do this in JS also? Because with FB Apps the URL is not always the same so instead of detecting a full URL I just want to search for my domain name within document.location.href to see if it exists and IF yes > Redirect back to FB.
I want to detect the double-press of the space key. However, I want a single press of a space key to have a different function. The double-tap of space should only count if the taps of space are no more than, say, a half second apart.
For example: The user hits space once, and javascript begins performing one action. 1/3rd of a second later, they hit the space bar again, and since that is within our threshold of 1/2 of a second, the action that began because the user hit the spacebar once should be cancelled, or undone (which I can write later) and the action when the user hits the spacebar twice should begin.
I have created a nice blog form for my users and I would like them to be able to use some aspects of HTML code that I have styled and they can utilise. The way I have this set up at the moment is, much like th reply boxes here, they can click on a button and the code (such as ) is automatically added to the textarea. The problem I have at the moment is that the cursor goes to the end of the content written so far and places whatever they have clicked at the end. I would like to be able to detect the cursor position and then they can add the various tags where they want them.
Also, is there a way I can get the cursor to automatically sit between the opening and closing tags that are generated (as can be seen here)??
function writeCodeTag(code) { var cache = document.getElementById('f').article.value; this.code = code; document.getElementById('f').article.value = cache + code; document.getElementById('f').article.focus(); }
This function adds the various code tags to the textarea... I have the same sort of thing for smilies.
I having a wrapper DIV (certain width say 400px) and i have some child DIVS which i want to add to it. And i want it to have a maximum height of 600px say.
I DONT want the wrapper DIV to have vertical scroll bars so i would like to add as many child DIVS (which contain text of indiscriminant length) until i can somehow detect that the wrapper has overflowed (ie the scrollbars have been implemented !) if it has then remove the last one and dynmically create a new DIV, and continue the cyclw until exhausted of child DIVS. Code:
Does anyone here know of a way using javascript to detect if a specific website is up (by accessing a specific url for example), and then once it responds to redirect the user to it?
I'm trying to detect keystrokes using Javascript. My code (so far) works in Opera and Safari, but not in Firefox, Netscape/SeaMonkey/Mozilla, or Chrome. (I have no idea if it works in IE; IE has other problems with my code.)What I've done is attached a onkeydown listener to the body tag. (I've also tried it with onkeypress and onkeyup.) Right now all I'm trying to do is detect a key press -- any key press -- and throw an alert as a result. I've tried it two separate ways -- with straight Javascript and with MooTools, which I'm using for the rest of my project.
The code I have is as follows:
mootools version $(document.getElementsByTagName('body')[0]).addEvent('keypress', function(event) { alert('key has been pressed.'); }); regular javascript version document.getElementsByTagName('body')[0].addEventListener("keypress", function() { alert('key has been pressed.'); }, false);
Both versions work in Opera and Safari. Interestingly enough, if I attach a click listener to the body using the exact same code as above, but changing the word 'keypress' to 'click', they both work in Firefox as well. I can't figure out how to get this key listener attached.