Questions tagged [onfocus]

onfocus is an event in HTML and JavaScript that triggers when the referenced object gains focus. This tag should be used only in conjunction with the primary language tag, and only for questions where the onfocus event is central to the issue(s) being addressed.

The focus event triggers when a visitor focuses on an element.

Not all elements are focusable by default. For example, INPUT and all types or form fields support this event, A supports it. As a counterexample, DIV doesn't support focus.

The list of elements types which support focusing is slightly different between browsers.

Tutorial

498 questions
74
votes
11 answers

How to change placeholder color on focus?

How to change the color of placeholder when focus the input field? I use this CSS code to set the default color, but how to change it on focus? ::placeholder { color: blue; }
Davide
  • 1,635
  • 1
  • 16
  • 29
69
votes
6 answers

react-navigation: Detect when screen, tabbar is activated / appear / focus / blur

Perviously when I wanted to make some actions when screen is opened I put them inside componentDidMount. For example I can fetch some data. like this. componentDidMount() { this.updateData(); } But with react-navigation componentDidMount occurs…
rendom
  • 3,417
  • 6
  • 38
  • 49
65
votes
4 answers

Vue.JS value tied on input having the focus

Is there a way to change a value in the model when an input gets/loses focus? The use case here is a search input that shows results as you type, these should only show when the focus is on the search box. Here's what I have so far:
cambraca
  • 27,014
  • 16
  • 68
  • 99
25
votes
8 answers

Testing input.focus() in Enzyme

How do I test input.focus() in enzyme. I am writing the script with react. My code is below: public inputBox: any; componentDidUpdate = () => { setTimeout(() => { this.inputBox.focus(); }, 200); } render() { return ( …
Sachin
  • 306
  • 1
  • 3
  • 8
23
votes
1 answer

Opposite of 'onFocus' in React

I have a scenario where there has to be a event triggered when the input selected goes out of Focus. There is already a onFocus event trigger when input is focused I need to know if there is an event that can…
Sijan Shrestha
  • 2,136
  • 7
  • 26
  • 52
22
votes
2 answers

Window focus and blur events not working correctly on Android browser

I found out that Javascript focus and blur events does not fire correctly on the Android browser, when attached to window, document or body. I wrote a simple test script which is working correctly on desktop browsers, but fails on Android stock…
istvan.halmen
  • 3,320
  • 1
  • 23
  • 29
19
votes
4 answers

Debugging onFocus event using Chrome Developer Tools? Can't return focus after break point

I'm trying to debug a JavaScript onFocus event attached to a bunch of text boxes on a page. The bug occurs when selecting a text box and then tabbing to the next text box. I'm trying to debug this by placing a break point in the onFocus event…
busoni34
  • 389
  • 1
  • 4
  • 13
19
votes
11 answers

How can restrict the tab key press only within the modal popup when its open?

I have a modal popup opened. I have accessibility requirement. So added ARIA related labels. But when i click tab key continuously focus going to the page behind the actual page. Added role="dialog" in html file But when modal opened i want only the…
Gnik
  • 7,120
  • 20
  • 79
  • 129
17
votes
1 answer

Type Email doesn't support selectionrange

I'm trying to set my cursor to the position of the beginning when I'm on focus of a text box. This is what I have: $("ID").focus(function () { var input = this; setTimeout(function() { input.setSelectionRange(0, 0); },…
Norman In
  • 171
  • 1
  • 4
13
votes
4 answers

Is it possible to write onFocus/lostFocus handler for a DIV using JS or jQuery?

I have a div and when the user clicks the div a function should be called. And when the user clicks something else (anything other than this div) another function should be called. So basically i need to have onFocus() and lostFocus() function calls…
Ivin
  • 4,435
  • 8
  • 46
  • 65
12
votes
6 answers

Automatically select all text on focus Xamarin

How to automatically select all text on focus in Entry,Editor,Label? Use Cross Platforms. Quantity.IsFocused = true; No work :(
Ibrahim
  • 949
  • 3
  • 12
  • 21
11
votes
2 answers

jQuery: How can I tell when a tab/window gains focus

Is there an event that I can register for that fires each time the user clicks on a tab, meaning that they were on my page's tab, clicked on another tab, then came back to my tab. EDIT: By tabs, I mean browser tabs, not jQueryUI tabs.
mtmurdock
  • 12,756
  • 21
  • 65
  • 108
10
votes
2 answers

Document visibilitychange versus window blur/focus, what is the difference, when to use which?

In ECMAscript (=Javascript) there are two ways to check if the user is away from your page or not. You can either listen for a "visibilitychange" event on the document or you can listen for "blur" and "focus" events on the window. Is there a…
HolyResistance
  • 594
  • 1
  • 8
  • 26
10
votes
5 answers

HTML input onfocus & onblur?

ok, today I'm making a helper HTML function. It looks like this: function Input($name,$type,$lable,$value= null){ if (isset($value)) { //if (this.value=='search') this.value = '' echo '
Adam Ramadhan
  • 22,712
  • 28
  • 84
  • 124
10
votes
1 answer

Java Key Bindings Not Working

I am trying to make key bindings in Java on a JPanel. I want a certain action to execute when I press the 'w' button. I follow the Java tutorial on making bindings, but the actionPerformed method does not execute (i.e. no text prints out). The…
user2640461
  • 215
  • 2
  • 6
1
2 3
33 34