Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

这是比较两个日期并确保一个比另一个更大的快速脚本。

在表单中的自定义HTML元素中键入以下脚本,并相应地修改表单字段名称。下面的示例显示了从“start_date”和“end_date”字段。

This is a quick script for comparing two dates and ensuring that one is larger than the other.

Type the following script in the Custom HTML element in your form and amend the form field name accordingly. Our example below shows a reading from the fields "start_date" and "end_date".

Code Block
langjavascript
<script type="text/javascript">
$('form').submit(function(){
	startDate = $("input[name='start_date']").val();
	endDate = $("input[name='end_date']").val();
	if( endDate < startDate ){
		alert("End Date must be larger than the Start Date. Please try again.");
		return false;
	}else{
		return true;
	}
});

</script>