Solved

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

Posted on 2010-11-27
2
336 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
2 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 250 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:jmatix
jmatix earned 250 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now