How to refresh a web page in html when the text box value change dynamically?
How to开发者_开发问答 refresh a web page in html when the text box value change dynamically?
I think you want the onChange javascript event.
<SCRIPT TYPE="text/javascript">
<!--
function checkEmail(mytext)
{
if(mytext.length == 0)
{
alert("You didn't type anything!");
}
}
//-->
</SCRIPT>
<FORM>
<INPUT NAME="email" onChange="doStuff(this.value)">
</FORM>
set document location to current value, and it will refresh!
document.location=document.location
Changing the value
property of an input element will not trigger its onchange()
handler.
You can reload the page with window.location.reload()
.
Per user's additional info in the comment, it sounds like -any- change needs an action.
This sounds very similar to this question: (whose title is misleading; no jquery is needed) How to detect a textbox's content has changed
It seems like the best way to do it is by using window.setInterval to poll the field, and if it changes from its original value, call window.location.reload(). 500ms for setInterval is probably plenty fast enough.
So:
<SCRIPT TYPE="text/javascript">
<!--
function doStuff()
{
var myElement = document.getElementById("stuff");
if(myElement.length > 0)
{
window.location.reload();
}
}
//-->
</SCRIPT>
<BODY onload="self.setInterval('doStuff()',500)">
<FORM>
<INPUT TYPE="text" ID="stuff" NAME="stuff">
</FORM>
</BODY>
精彩评论