[英]How to load input from textbox without using submit button? javascript?
[英]Textbox input ,retrieve values from database without submit button in php
<html>
<head>
<title></title>
</head>
<body>
<div style="background: rgb(238, 238, 238) none repeat scroll 0% 0%; border: 1px solid rgb(204, 204, 204); padding: 5px 10px; text-align: center;"><span style="color:#008000;"><span style="font-size: 20px;"><span style="font-family: lucida sans unicode,lucida grande,sans-serif;">BOOKS RENEWAL</span></span></span></div>
<p style="text-align: center;"> </p>
<table align="center" border="0" cellpadding="1" cellspacing="1" dir="ltr" height="79" style="height: 400px;" width="580">
<tbody>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"> <span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;">Roll Number</span></span></span></td>
<td colspan="4"><input name="Rollno" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Name </span></span></span></td>
<td colspan="4"><input name="Name" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Branch </span></span></span></td>
<td><input name="Branch" type="text" /></td>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;">Semester</span></span></span></td>
<td colspan="2"><input name="Semester" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Call Number </span></span></span></td>
<td><input name="Callno" type="text" /></td>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;">Accession Number</span></span></span></td>
<td colspan="2"><input name="Acc_no" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Author Name</span></span></span></td>
<td colspan="4" rowspan="1"><input name="Auth_name" size="69" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Title Name </span></span></span></td>
<td colspan="4" rowspan="1"><input name="title" size="69" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap; width: 50px;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Date of Issue</span></span></span></td>
<td colspan="2" rowspan="1" style="white-space: nowrap; width: 300px;"><input name="Date_iss" size="10" type="text" /></td>
<td rowspan="1" style="white-space: nowrap; width: 50px;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;">Due Date</span></span></span></td>
<td rowspan="1"><input name="Due_dt" size="10" type="text" /></td>
</tr>
<tr>
<td style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Due Amount </span></span></span></td>
<td colspan="2" rowspan="1"><input name="Due_amt" size="5" type="text" /></td>
<td rowspan="1" style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;">Amount Paid</span></span></span></td>
<td rowspan="1"><input name="Amt_paid" size="5" type="text" /></td>
</tr>
<tr>
<td colspan="5" style="white-space: nowrap;"><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> Balance</span></span> </span><input name="Balance" size="5" type="text" /></td>
</tr>
</tbody>
</table>
<p><span style="color:#0000FF;"><span style="font-size: 16px;"><span style="font-family: tahoma,geneva,sans-serif;"> </span></span></span></p>
<p style="text-align: center;"><input name="OK" type="button" value="OK" /> <input name="Exit" type="button" value="Exit" /></p>
</p>
</p>
</body>
</html>
主席先生,我的问题是,首先我将输入Rollno,而无需提交,我必须从数据库中获取与rollno有关的详细信息,而无需刷新,然后在同一页面中,我将输入登录号,然后再次必须从数据库。 可以使用vb完成此操作,但是如果我想在PHP中进行操作,该怎么做。
您可以使用AJAX实现目标。 如果你不知道Ajax,请在这里阅读。 上述解决方案将添加以下内容:
<input name="Rollno" type="text" onblur="myFunction(this.value)" />
假设您要在
<input name="Branch" type="text" />
然后将其更改为
<input name="Branch" type="text" id="change" value=""/>
现在是javascript部分
<script>
function myFunction(r){
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("change").value= xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdetails.php?roll="+r,true);
xmlhttp.send(); }
</script>
现在的PHP部分
if(isset($_GET['roll'])){
// get the data for roll from the database and simply echo them here;}
}
这只是帮助您了解Ajax的最小解决方案。
您也可以使用jQuery。
<input type="text" id="get">
<div id="result"></div>
您的jQuery代码。
$("#get").blur(function (){
var val = $('#get').val();
$.post('data.php', {value: val}, function (data) {
$('#result').html(data);
}
}
在你的php文件中
if(isset($_POST['value'])){
$results = database query/results
echo $results;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.