开发者

Refreshing page without losing textbox value

I have a webpage game, it's multiplayer so the page has to refresh every few seconds so the player can keep track and know when it is their turn...

It refreshes using the code:

<META HTTP-EQUIV="Refresh" CONTENT="3; URL=game.php">

Also the game page has a 'chatroom' in it, which basically allows the players to 'chat' to each other, the chatroom consists of a div (which holds text from database) and a HTML form textbox/textfield and a HTML form submit button.

But because the page refreshes if the user is in the middle of typing something like 'Hello players' and gets to 'Hel' before the page automatticly refreshes the textfield/textbox loses the value ('Hel')

How can I easily put the 'Hel' value back into textbox/textfield as if it never was gone so the user can continue t开发者_Python百科yping his message?

Or is there a way to never lose the value?


Have a look at http://www.w3schools.com/JS/js_cookies.asp, it shows you how to set and get cookies in JS. You could set the textbox value on page load from the cookie and set the cookie value whenever the contents of the textbox changes. I do have to agree that this seems an odd and awkward way of doing this but I have not seen the full thing so...

I can probably give you example code for this but I have not done any JS for a few months now and am currently in VB.Net mode. If someone else could provide a basic example of this I would be really grateful.


Just use javascript and update all you need with AJAX.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜