开发者

Getting the value from a prompt box

开发者 https://www.devze.com 2023-03-10 06:05 出处:网络
Hello I\'m trying to make a simple web chat, and I want the user to choose his name when he first load the chat page and for this I\'m using this function:

Hello I'm trying to make a simple web chat, and I want the user to choose his name when he first load the chat page and for this I'm using this function:

function Login(un)
{
var x=prompt("Please enter your name","");
var xmlhttp;
if (window.XMLHttpRequest)
  {// Използваните браузъри
  xmlhttp=new XMLHttpRequest();
  }
else
  {// Кой ли ползва тези версии..
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
    xmlhttp.open("GET","login.php?u="+un,true);
    xmlhttp.send();
}

I put this in the head section and then in the body onload... I call the function but can't figure out how to extract the text from the prompt box.I tried

login(getElementsByName('x').开发者_开发百科value)

But obvously that's not the way, so, please help. Thanks Leron


var x=prompt("Please enter your name","");

Then x has the value entered in the prompt.


var login = getElementsByName('loginboxname').value;

Just make sure you replace "loginboxname" with the actual name of your login box. The variable "login" should then the value of that box.

0

精彩评论

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