I have a form in my portlet in liferay 6. I want to validate data before sending data from form, but I cannot. I want that if my field is empty, the form does not submit.
My jsp code:
<script>
function submitForm18() {
var pre=document.forms['<portlet:namespace/>myFormpostcode']['<portlet:namespace/>pre'].value;
if (pre == "" || pre == null) {
alert("errrror.");
forms['<portlet:namespace/>myFormpostcode']['<portlet:namespace/>pre'].focus();
return false;
}
document.forms['<portlet:namespace/>myFormpostcode'].submit();
}
</script>
<aui:form action="<%= myUrl%>" method="post" name="myFormpostcode" id="send_info" onsubmit="return submitForm18(); return false;">
<liferay-ui:message key="pre-code" /> : <liferay-ui:message key="without-zero" />
<aui:input size="4" maxlength="4" name="pre" type="text" label=""></aui:input>
<aui:button type="submit" value="send" name="KeyNB" cssClass="buttom-submit" />
</aui:form>
This code shows alert if field is empty and submits form but I want to show alert(validate form) and don't submit if form data is not valid.