Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update textbox with value written in a file (Simulate as if user has entered it)

Posted on 2010-11-27
2
Medium Priority
?
345 Views
Last Modified: 2012-05-10
Please let me know how I can create an HTML page with a text box that updates its value periodically (say every 2 seconds) with a value written in a text file.
The code attached does this for me.

I now need one additional feature - I need to simulate the user entering the value (from the file) into the text box by simulating the following procedure:

1. Clicking on the textbox to change focus
2. Entering the value (read from the file)
3. Clicking outside the textbox to remove focus (The click event must be simulated)

PS: The click event must be simulated. It is not enough if just the focus is changed.

If possible, please provide some sample code. Thanks!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script language="javascript">
	setInterval( '$("#textboxID").val( $.ajax({"url":"file.text", "async":false}).responseText );', 2000 );
</script>
</head>
<body>
<input id="textboxID" />
</body>
</html>

Open in new window

0
Comment
Question by:dshrenik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 1000 total points
ID: 34224352

Are you looking for something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26641836.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script language="javascript">

var textBox = null;
var index = 0;
var text = "";

function update( box, value ) {
  if ( arguments.length > 1 ) {
    textBox = box;
    text = value;
    textBox.focus();
    index = 0;
  }
  textBox.val( text.substr( 0, ++index ) );
  setTimeout( "update()", 333 );

  if ( index == text.length ) textBox.blur();
}

function repeat() {
  update( $("#textboxID"), $.ajax({"url":"https://updates.opendns.com/nic/update", "async":false, "username":"bogus", "password":"bogus"}).responseText );
}

$(document).ready( function() {

  update( $("#textboxID"), "Loading..." );
  setInterval( 'repeat()', 4000 );

});
</script>
</head>
<body>
<input id="textboxID" />
</body>
</html>

Open in new window

0
 
LVL 16

Assisted Solution

by:Justin Mathews
Justin Mathews earned 1000 total points
ID: 34232222
Try this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script language="javascript">
$(document).ready(function(){
	var txt =  $.ajax({"url":"file.text", "async":false}).responseText;
	$("#textboxID").focus();
	$._int = setInterval("setText('"+txt+"')", 300 );
});

function setText(txt)
{
	var t = $("#textboxID").val();
	if (t.length==txt.length)
	{
		clearInterval($._int);
		$("#textboxID").blur();
		return;
	}
	$("#textboxID").val(txt.substr(0, t.length+1));
}


</script>
</head>
<body>
<input id="textboxID" />
</body>
</html>

Open in new window

0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question