一旦我们输入数据并提交丢失的数据。.plz帮助解决此问题 每当提交正确的数据时,我都需要显示更新的表。每当我尝试以表单的形式提交数据时,它都会更新表格,并且该页面就像是刷新的新页面。
`
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-url", "--url", help="Enter the URL")
parser.add_argument("-fname", "--fname", help="Enter Filename")
args = parser.parse_args()
grab(args.url, args.fname)
if __name__ == "__main__":
main()
答案 0 :(得分:1)
尝试使用普通按钮代替提交按钮,这可以解决您的问题。
<body>
<div>
<form name="dataform">
First name:
<input type="text" id="fname" name="first_name">
Last name:
<input type="text" id="lname" name="last_name">
Age:
<input type="number" id="age" name="age" min="1" max="100">
Email:
<input type="email" id="email" name="email">
<input type="button" name="submitdata" value="Submit" onclick="updatetable()"/>
</form>
</div>
<br><br>
<table id="table1" cellpadding="30">
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Email</th>
</table>
</body>
public List<Client> getAllCustomers() throws SQLException {
List<Client> listOfClients = new ArrayList<Client>();
String sql = "SELECT * FROM `client`";
result = statement.executeQuery(sql);
while (result.next()) {
Client client = new Client();
client.setName(result.getString("namee"));
client.setSurname(result.getString("surname"));
// ... and so on
listOfClients.add(client);
}
return listOfClients;
}
答案 1 :(得分:1)
单击表单时,表单内的提交按钮(<input type="submit">
)将提交表单,刷新页面。如果您不想提交表单,请将按钮更改为<input type="button">
,它将不提交表单。您还应该使用查询选择器来获取表单内的所有输入。
<html>
<head>
<script type="text/javascript">
function updatetable()
{
alert("hello");
var fname = document.getElementById("fname");
var lname = document.getElementById("lname");
var age = document.getElementById("age");
var email = document.getElementById("email");
if(fname.value == "" || lname.value == "" || age.value == "" || email.value == "")
{
alert("Please enter data in all the fields");
return;
}
if(age.value < 1 || age.value > 100)
{
alert("enter age properly");
return;
}
var tab = document.getElementById("table1");
var row = tab.insertRow(-1);
var inputs = document.querySelectorAll('form[name=dataform] input');
//var cell = row.cells;
for(var i=0;i<4;i++)
{
var cell = row.insertCell(i);
cell.innerHTML = inputs[i].value;
}
}
</script>
</head>
<body>
<form name="dataform">
First name:
<input type="text" id="fname" name="first_name">
Last name:
<input type="text" id="lname" name="last_name">
Age:
<input type="number" id="age" name="age" min="1" max="100">
Email:
<input type="email" id="email" name="email">
<input type="button" name="submitdata" value="Submit" onclick="updatetable()"/>
</form>
<br><br>
<table id="table1" cellpadding="30">
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Email</th>
</table>
</body>
</html>
答案 2 :(得分:0)
我刚刚深入检查了您的代码,发现您有2个错误
第一个html
替换
<input type="submit" name="submitdata" value="Submit" onclick="updatetable()"/>
使用
<input type="button" name="submitdata" value="Submit" onclick="updatetable()"/>
for循环内的javascript中的秒数
替换
cell.innerHTML=document.forms["dataform"].elements[i].value;
使用
cell[i].innerHTML=document.forms["dataform"].elements[i].value;
这是您的代码的有效演示 https://jsfiddle.net/cxz3Lwou/14/
希望有帮助 :)