[jQuery] Re: How to simulate a human-triggered event?

2009-06-17 Thread waseem sabjee
$(#txt).focus() function() {
// this is when the user tabs to the control or clicks on it
});

$(#txt).blur() function() {
// when the user tabs out or clicks on something else
});

if you check the JQuery events page you will other helpful event

like :
keyup
keydown
mouseup
mousedown

you can usually detect input change on key up event

var txt  = $(#myid).text();

$(#myid).keyup(function() {

if(txt != $(this),val() {
txt = $(this).val();
alert(input changed)l
}

}

});


so a script for your solution would be

$(#source).keyup(function() {

$(#target).attr{(
value: $(#source).attr(value)
});

});

On Tue, Jun 16, 2009 at 11:40 PM, Andy Matthews li...@commadelimited.comwrote:


 Assuming the second input field is triggered by a user instigated event,
 then you could just trigger that event.

 $('input#change').click(function() {
$('input#source').attr('value', 'This is the value changed by a
 button');
 $('something').trigger('blur',fn);
 });

 -Original Message-
 From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
 Behalf Of Jay
 Sent: Tuesday, June 16, 2009 3:46 PM
 To: jQuery (English)
 Subject: [jQuery] How to simulate a human-triggered event?


 Hi, I'm trying to change the value of an input field (target) which depends
 on another input (source). It works well when I manually change the source
 value. But if I changed the source value with another button, the target
 value remains the same. Here's the code...

 $(document).ready(function() {
$('input#change').click(function() {
$('input#source').attr('value', 'This is the value changed
 by a button');
});

$('input#source').change(function() {
$('input#target').attr('value',
 $('input#source').attr('value'));
});
 });

 pSource: input type=text name=target id=source size=60
 value= / input type=button id=change value=change source value
 //p
 pTarget: input type=text name=target id=target size=60
 value=This is the original value, type something in source to change
 //p

 So how could the target input detect if there's a change within the source
 input without manually changing it's value? Thanks





[jQuery] Re: How to simulate a human-triggered event?

2009-06-16 Thread Andy Matthews

Assuming the second input field is triggered by a user instigated event,
then you could just trigger that event.

$('input#change').click(function() {
$('input#source').attr('value', 'This is the value changed by a
button');
$('something').trigger('blur',fn);
});

-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of Jay
Sent: Tuesday, June 16, 2009 3:46 PM
To: jQuery (English)
Subject: [jQuery] How to simulate a human-triggered event?


Hi, I'm trying to change the value of an input field (target) which depends
on another input (source). It works well when I manually change the source
value. But if I changed the source value with another button, the target
value remains the same. Here's the code...

$(document).ready(function() {
$('input#change').click(function() {
$('input#source').attr('value', 'This is the value changed
by a button');
});

$('input#source').change(function() {
$('input#target').attr('value',
$('input#source').attr('value'));
});
});

pSource: input type=text name=target id=source size=60
value= / input type=button id=change value=change source value
//p
pTarget: input type=text name=target id=target size=60
value=This is the original value, type something in source to change
//p

So how could the target input detect if there's a change within the source
input without manually changing it's value? Thanks