[英]Dont post the form if the "caseref" field has less than 10 characters
有人可以幫忙嗎?
我無法讓它工作,如果“caseref”字段中的字符少於 10 個,我需要表單做的就是不發布,html 是:
<html>
<head>
<title>Update</title>
</head>
<body>
<form method="POST" action="update.php">
<table height="408" width="527">
<tr>
<td height="25" width="334"><font face="Calibri" size="6">Case Ref:<br>
<input type="text" name="caseref" size="25" maxlength="13 value=""> </font></td>
</tr>
<tr>
<td height="25" width="334"><font face="Calibri" size="6">Engineers Name:<br>
<select name="name">
<option value="Dave" selected>Dave</option>
<option value="Terry">Terry</option>
<option value="Piere">Piere</option>
<option value="Steve">Steve</option>
<option value="Craig">Craig</option>
<option value="Faz">Faz</option>
</select></font></td>
</tr>
<tr>
<td height="164" width="334"><font face="Calibri" size="6">Update:<br>
<textarea cols="17" name="notes" rows="10"></textarea></font></td>
</tr>
<tr>
<td height="27" width="475">
<div align="center">
<p align="left"><font face="Calibri" size="6"><input type="submit" value="Submit"></font></p>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
所以如果 case ref 字段少於 10 個字符,那么它需要發布一個消息框說“請再試一次!”
先感謝您
您可以做的是將<input type="submit" value="submit">
更改為具有 onclick 功能的普通按鈕。 在此函數中,您可以使用 javascript 檢查 ref 字段的長度並做出相應的反應。
您可以在此處查看工作示例
<input type="text" name="caseref" size="25" maxlength="13" id="caseref" value="">
您好,您可以使用 jQuery。
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$('input[type="submit"]').on("click",function(){
e.preventDefault(); // prevents default
var myLength = $("#caseref").val().length;
if(myLength > 10){
$('#form').submit();
}else{
$('#message').html("Please, try again");
}
});
</script>
您可以更改這樣的鏈接的提交按鈕
<input type="submit" value="Submit">
<!-- change for-->
<a href="javascript:;" id="button">Send</a>
還要替換您的表單標題
<form method="POST" id="form" action="update.php">
然后你改變點擊事件
$('#button').on("click",function(){
var myLength = $("#caseref").val().length;
if(myLength > 10){
$('#form').submit();
}else{
$('#message').html("Please, try again");
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.