I am trying to input numbers into a input boxes from buttons. I am having a hard time figuring out how to find which input box has focus. Is there anything to tell me which input box has focus?
Asked
Active
Viewed 78 times
1
-
name on server side, or id via client side – Royal Bg Jan 06 '14 at 17:58
-
you say javascript... jQuery? – Digital Chris Jan 06 '14 at 18:01
-
1As you say you are setting the value with button, you must be using Javascript already. Care to share what you have already? – Moe Tsao Jan 06 '14 at 18:01
3 Answers
0
Perhaps create a new selector:
jQuery.expr[':'].focus = function( elem ) {
return elem === document.activeElement && ( elem.type || elem.href );
};
and test it like this:
if ($("#idOfTextBox").is(":focus")) {
...
}
0
Not sure if this is what you're trying to do:
It creates a button next to a text field, then you clic on the button and it sets focus to the text field
<form name="myform2">
<input type="text" name="mytextfield2">
<input type="button" name="mybutton" value="Set Focus" OnClick="document.myform2.mytextfield2.focus();">
</form>
Or with javascript:
<script type="text/javascript" language="JavaScript">
document.forms['myform'].elements['mytextfield'].focus();
</script>

Frakcool
- 10,915
- 9
- 50
- 89