简体   繁体   中英

required field in html form works in chrome but not mobile or ie (done in wordpress)

I am building a form using html in wordpress. The fields that need to be required work in chrome (giving a please fill out this field when the submit button is pressed without information in the field) however it will not work in IE or mobile, it just allows the form to be submitted. Here is a sample of a field

Last name: *

input type="text" name="lastname" value="" maxlength="50" required="required"  

I dont know whats going on here and Im pretty new so any help would be appreciated

(edit with answer) This is what I ended up doing and it works now thanks for the responses

<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["firstname"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}
</script>
</head>
<body>
<form name="myForm" form action="dlcplateFormTest.php"  onsubmit="return validateForm()"                   method="POST">
<tr>
<td>Last name: *</td>
<td><input type="text" name="lastname" value="" maxlength="50" required="required"  />            </td>
</tr>
<tr>
<input type="submit" value="Submit" /><input type="reset" value="Reset" />
</form>
</body>
</html>

您需要编写一个JavaScript函数来检查字段是否为“”,如果为“”,则取消请求

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM