tags:

views:

55

answers:

5

Hello,

When the value is entered, I want an alert, its a copy/paste text box, using jquery

('#test).bind('onblur',function(){
  var h = ('#test).attr('value');
alert(h);
});


<input type=text id=test>

Thanks Jean

+1  A: 
  • missing quote behind your selector
  • typo in function()

  • replace 'onblur' with 'blur' or 'focusout'

  • use var h = $(this).val();

blur and focusout only fire wenn that element loses the focus.

Kind Regards

--Andy

jAndy
A: 

Not knowing your full HTML source, I would imagine:

$('#test').blur(function()
{
   alert(this.value);
});

should do the trick. The code you have entered doesn't seem to be valid JavaScript, and it looks like you might be trying to complicate the event attaching and handler with too much code.

Tejs
@Tejs: You should replace `this.value` with `$(this).val()`
Sarfraz
+2  A: 

Try this:

<input type="text" id="test" />

JQuery

$(function(){
    $('#test').blur(function(){
      alert($(this).val());
    });
});
Sarfraz
.value is not going to be a property on a jQuery object. There is no need to encase 'this' inside a jQuery construct.
Tejs
@Tejs: fixed it before even your comment :)
Sarfraz
@Sarfraz Does not seem to be working.
Jean
@Sarfaz Heh, looks similar to mine! I'll upvote =D
Tejs
@Jean: Have you included the jquery library in your page before that code?
Sarfraz
@sarfraz, yes, this is just an addition I am doing, there is no js error, the alert box just does not bling!
Jean
@Jean: did you try `focusout` instead of `blur`? and is the textbox created on-the-fly?
Sarfraz
@sarfraz did focusout, just does not move, also the blur, now I wonder why, it works perfectly with .bind('click')
Jean
@sarfraz check this link out http://api.jquery.com/blur/
Jean
+1  A: 

Not quite sure what you want, but is it something like this?

$("#test").change(function() { alert($(this).val()); });

The alert shows the text entered in the box when it is changed.

Dan Diplo
he is newbie, you are missing `ready` handler.
Sarfraz
.change?.........
Jean
I guessed change might be more appropriate than blur. But it's easily substituted for another event - http://api.jquery.com/category/events/
Dan Diplo
A: 
('#test input').bind('blur',function(){
  var h = ('#test).attr('value');
alert(h);
});

adding an input in the selector should work for the blur

Jean
Will someone upvote the question and this answer
Jean
if this is the answer, then you can mark it as the answer. it doesn't need to be upvoted
Sam Holder