<html><br>
<head><br>
<title>fetch data from library records</title><br>
<script> <br>
var request;<br>
function sendInfo()<br>
{<br>
alert("my name is rakesh:");<br>
document.getElementById("rakesh").innerHTML = "Hello JavaScript!";<br>
var v1=document.myform.username.value;<br>
var v2=document.myform.password.value;<br>
var v3=document.myform.idate.value;<br>
var v4=document.myform.ddate.value;<br>
var url="index.jsp?val1="+v1+"&val2="+v2+"&val3="+v3+"&val4="+v4;<br>
if(window.XMLHttpRequest){<br>
request=new XMLHttpRequest();<br>
}<br>
else if(window.ActiveXObject){<br>
request=new ActiveXObject("Microsoft.XMLHTTP");<br>
}<br>
try<br>
{<br>
request.onreadystatechange=getInfo;<br>
request.open("GET",url,true);<br>
request.send();<br>
}<br>
catch(Exception e)<br>
{<br>
alert("Unable to connect to server");<br>
}<br>
}<br>
function getInfo(){<br>
if(request.readyState==4){<br>
var val=request.responseText;<br>
document.getElementById('rakesh').innerHTML=val;<br>
}<br>
} <br>
</script><br>
</head><br>
<body><br>
<form name="myform" id="mform"><br>
<table><br>
<tr><br>
<td>Enter UserName : </td><br>
<td><input type='text' name="username" id="username"/></td><br>
</tr><br>
<tr><br>
<td>Enter PassWord : </td><br>
<td><input type='password' name="password" id="password"/></td><br>
</tr><br>
<tr><br>
<td>Enter IssueDate: </td><br>
<td><input type='text' name="idate"/></td><br>
</tr><br>
<tr><br>
<td>Enter DepositDate:</td><br>
<td><input type='text' name="ddate"/></td><br>
</tr><br>
<tr><br>
<td><input type="button" name="sub" value="fetch" onClick="sendInfo()"></td><br>
</tr><br>
</table><br>
</form><br>
<span id="rakesh"></span><br>
</body><br>
</html><br>
答案 0 :(得分:0)
我修改了你的代码。 请在下面查看。
<html>
<head>
<title>fetch data from library records</title>
</head>
<body>
<form name="myform" id="mform">
<table>
<tr>
<td>Enter UserName : </td>
<td><input type='text' name="username" id="username"/></td>
</tr>
<tr>
<td>Enter PassWord : </td>
<td><input type='password' name="password" id="password"/></td>
</tr>
<tr>
<td>Enter IssueDate: </td>
<td><input type='text' name="idate"/></td>
</tr>
<tr>
<td>Enter DepositDate:</td>
<td><input type='text' name="ddate"/></td>
</tr>
<tr>
<td><input type="button" name="sub" value="fetch" onclick="sendInfo()"></td>
</tr>
</table>
</form>
<span id="rakesh"></span>
</body>
<script type="text/javascript">
var request;
function sendInfo()
{
alert("my name is rakesh:");
document.getElementById("rakesh").innerHTML = "Hello JavaScript!";
var v1=document.myform.username.value;
var v2=document.myform.password.value;
var v3=document.myform.idate.value;
var v4=document.myform.ddate.value;
var url="index.jsp?val1="+v1+"&val2="+v2+"&val3="+v3+"&val4="+v4;
if(window.XMLHttpRequest){
request=new XMLHttpRequest();
}
else if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP");
}
try
{
request.onreadystatechange=getInfo;
request.open("GET",url,true);
request.send();
}
catch(Exception)
{
alert("Unable to connect to server");
}
}
function getInfo(){
if(request.readyState==4){
var val=request.responseText;
document.getElementById('rakesh').innerHTML=val;
}
}
</script>
</html>