...

View Full Version : User is typing



Zangeel
05-27-2009, 08:31 AM
Wondering if I could get some help with this. Im trying to find a static way to see if someones typing, entered text etc...

Currently, if you are typing, or enter anything in the input box it will say you are typing, and if u delete it, the message dissapears.. is there a way where if you're not typing at all it can say "You entered text" or something? maybe a way to time when the last key was pressed?




<script type="text/javascript">

var Static = "You are typing.";

function GetKeyUp(folder) {
var temp = document.getElementById('textin').value;
if (temp == 0) {
document.getElementById('typing').innerHTML = "";
}
else {
document.getElementById('typing').innerHTML = Static;
}

}

</script>

<input id="textin" type="text" name="box" onkeyup="GetKeyUp(this)" /> <input type="submit" value="Submit" name="submit" />
<br /><br />
<div id="typing" /></div>

Philip M
05-27-2009, 08:42 AM
Surely the user knows that he is typing / has typed something and does not need informing?


var Static = "You are typing.";
var typed = "You have typed something";
var tim;

function GetKeyUp(folder) {
window.clearTimeout(tim);
var temp = document.getElementById('textin').value;
if (temp == 0) {
document.getElementById('typing').innerHTML = "";
}
else {
document.getElementById('typing').innerHTML = Static;
tim = setTimeout("haveTyped()", 2000);
}
}

function haveTyped() {
document.getElementById('typing').innerHTML = typed;
}
</script>

<input id="textin" type="text" name="box" onkeyup="GetKeyUp(this)" /> <input type="submit" value="Submit" name="submit" />
<br /><br />
<div id="typing" /></div>



<input id="textin" type="text" name="box" Why different element name and id?

"Seize the day, put no trust in the morrow!" [Carpe diem, quam minimum credula postero.]
Horace - Roman lyric poet & satirist (65 BC - 8 BC)

eddjc
05-27-2009, 10:06 AM
this may or may not work:




<input type = "text" onblur="isNotTyping();" onkeyup = "isTyping();" value = "" />
<p id = "response"></p>

<script>
var typing = false;

function isTyping () {

typing = true;
document.getElementById("response").innerHTML = "You are typing";

}

function isNotTyping () {

if(typing) {

typing = false;
document.getElementById("response").innerHTML = "";

}

}
</script>




of course you could modify it to timeOut if the user stops typing for couple of seconds...




<input type = "text" onblur="isNotTyping();" onkeyup = "isTyping();" value = "" />
<p id = "response"></p>

<script>
var typing = false;
var timing = false;
var timer;

function isTyping () {

typing = true;
document.getElementById("response").innerHTML = "You are typing";

if (timing) clearTimeout(timer);
timer = setTimeout('isNotTyping();', 2000);
timing = true;

}

function isNotTyping () {

if(typing) {

typing = false;
timing = false;
document.getElementById("response").innerHTML = "";

}

}
</script>



And to get rid of the message when the field is empty:




<input type = "text" onblur="isNotTyping();" onkeyup = "if (this.value == '') isNotTyping(); else isTyping();" value = "" />
<p id = "response"></p>

<script>
var typing = false;
var timing = false;
var timer;

function isTyping () {

typing = true;
document.getElementById("response").innerHTML = "You are typing";

if (timing) clearTimeout(timer);
timer = setTimeout('isNotTyping();', 2000);
timing = true;

}

function isNotTyping () {

if(typing) {

typing = false;
if (timing) clearTimeout(timer);
timing = false;
document.getElementById("response").innerHTML = "";

}

}
</script>

Philip M
05-27-2009, 10:53 AM
Sadly eddjc's script does not address the issue raised by the OP.

"is there a way where if you're not typing at all it can say "You entered text" or something? maybe a way to time when the last key was pressed?"

eddjc
05-27-2009, 11:34 AM
ach - it's mainly there. Anyone with half a brain can adapt the script I put up there to do that (hint: change the function setTimeout was leading to, and the else statement in "onKeyUp"). Anyway I was just trying to be helpful...

in fact, what the hell:


<input type = "text" id = "text_field" onblur="isNotTyping(this.value);" onkeyup = "if (this.value == '') isNotTyping(this.value); else isTyping();" value = "" />
<p id = "response"></p>

<script>
var typing = false;
var timing = false;
var timer;

function isTyping () {

typing = true;
document.getElementById("response").innerHTML = "You are typing";

if (timing) clearTimeout(timer);
timer = setTimeout('isNotTyping(document.getElementById('text_field').value);', 2000);
timing = true;

}

function isNotTyping (string) {

if(typing) {

typing = false;
if (timing) clearTimeout(timer);
timing = false;
if (string != '') document.getElementById("response").innerHTML = "You typed something";
else document.getElementById("response").innerHTML = "";

}

}
</script>

better?

Edd



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum