开发者

How to refresh a web page in html when the text box value change dynamically?

开发者 https://www.devze.com 2023-02-16 10:42 出处:网络
How to开发者_开发问答 refresh a web page in html when the text box value change dynamically?I think you want the onChange javascript event.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消