JQuery gets the value of the element: onfocus = "inputInlineHint (self);"

I have an input field that calls the "inputInlineHint (self)" function when blurring and focusing. He also passes by himself ...

<input type="text" id="one" class="textbox" value="Your Name" onfocus="inputInlineHint(self);" onblur="inputInlineHint(self);" />

Now I would like to get the current value of the field:

function inputInlineHint(e) {

  var theValue = '';

  //Now i need to retrieve the value... but how?
}

Hope you guys can help me with this ... should be pretty simple, but I'm new to jquery.

Thanks in advance!

+3
source share
3 answers
  • Skip thisno self. self- undefined.
  • Rename the variable from eto another. etraditionally used to get an event object, but you do not assign a function as an event handler.
  • whatever_you_renamed_e_to.value
+5

, jQuery, jQuery :

$(document).ready(function() {
    $('#one').blur(function() {
        var val = $(this).val();
        // rest of processing, etc.   
    })
    .focus(function() {
        var val = $(this).val();
        // rest of processing, etc.
    });    
});
+4

jQuery, script :


$(function() {
   $('#one').focus(function() {
      var value = $(this).val();  /// this is now the value
   }).blur(function (){
      var value = $(this).val();  /// same again
   );
);
+4
source

Source: https://habr.com/ru/post/1733503/


All Articles