send text with jquery and timer
The idea for my script is to send text from a select menu or a text field to a text area. So far I am able to get the select menu working when I pick an option, but for the text field when i type something it doesn't send anything. Also I would like to add a time to this script so that when a user selects an option or types something in it will send.
Right now it only works woth the select menu...not开发者_如何学Python sure how to also make it work for the text field and add the timer :(
<select id="status" name="status">
<option value=""></option>
<option value="Away">Away</option>
<option value="Busy">Busy</option>
<option value="Out To Lunch">Out To Lunch</option>
<option value="Offline">Offline</option>
</select>
<input name="custom_status" type="text">
<div id="counter"></div>
as
$(function() {
$("#status").change(function() {
$("textarea[name=mess]", parent.frames['form'].document).val($(this).val());
});
$("#custom_status").change(function() {
$("textarea[name=mess]", parent.frames['form'].document).val($(this).val());
});
});
It would be good to add id to custom status:
<input id="custom_status" name="custom_status" type="text" />
Then you can run function on both parts at the same time:
$("#status, #custom_status").bind('change keyup',function(){
$("textarea[name=mess]", parent.frames['form'].document).val($(this).val());
});
And handle timeout like this:
var callAway = false;
$('body').bind('mousemove keyup',function(){
clearTimeout(callAway);
callAway = setTimeout(function(){
$("#counter").text("Away");
},5000);
})
Fiddle: http://jsfiddle.net/eC9L6/
$("[name='custom_status']").change(function() {
$("textarea[name=mess]", parent.frames['form'].document).val($(this).val());
});
or
$("[name='custom_status']").bind('keyup change', function() {
$("textarea[name=mess]", parent.frames['form'].document).val($(this).val());
});
Your selector is wrong, there's no input with the id custom_status, but an input with the name custom_status.
精彩评论