请帮我这个脚本 [英] Please help me on this script

查看:61
本文介绍了请帮我这个脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我需要编写一个Javascript来计算日期差异以及

作为日期比较。当我尝试嵌入下面的脚本,它正在工作

,但是即使条件评估为
false,页面仍在提交。请让我知道原因是什么下面的问题

脚本。

函数ValidateDate()

{


var fromDate = new

Date(document.getElementById(" txtFromFiledDate")。v alue);

var toDate = new

Date(document.getElementById (" txtToFiledDate")。val ue);

var diffDate = new Date();

diffDate =(toDate - fromDate);

diffDate =((((diffDate / 1000)/ 60)/ 60)/ 24);

alert(" Difference is:" + diffDate);

alert(diffDate> 30);

if(diffDate< 0){alert(开始日期不能在结束日期之后!)

返回false;}

if(diffDat e> 30&& diffDate< 0){alert(请在

范围内输入日期)

返回false;}

返回true;

}

谢谢,

Vishnu


Hi,

I need to write a Javascript which calculates datedifference as well
as date comparision.When i try to embed the below script,it is working
well,but the page is submitting even when the condition evaluates to
false .Please let me know the reason what is the problem in the below
script.
function ValidateDate()
{

var fromDate=new
Date(document.getElementById("txtFromFiledDate").v alue);
var toDate=new
Date(document.getElementById("txtToFiledDate").val ue);
var diffDate=new Date();
diffDate = (toDate - fromDate);
diffDate = ((((diffDate / 1000) / 60) / 60) / 24);
alert("Difference is: " + diffDate);
alert(diffDate>30);
if(diffDate<0){alert("Start Date cannot be after End Date!")
return false;}
if(diffDate>30 && diffDate<0) {alert("Please enter the date in
Range")
return false;}
return true;
}
Thanks,
Vishnu

推荐答案

se****@gmail.com 写道:
se****@gmail.com wrote:

>




我需要编写一个Javascript来计算日期差异以及

作为日期比较。当我尝试嵌入下面的脚本,它正在工作

,但是即使条件评估为
false,页面仍在提交。请让我知道原因是什么问题在下面

脚本。


函数ValidateDate()

{


var fromDate = new

Date(document.getElementById(" txtFromFiledDate")。v alue);

var toDate = new

Date( document.getElementById(" txtToFiledDate")。val ue );

var diffDate = new Date();

diffDate =(toDate - fromDate);

diffDate =((((diffDate / 1000)/ 60)/ 60)/ 24);

alert(差异是: + diffDate);

alert(diffDate> 30);

if(diffDate< 0){alert(开始日期不能在结束日期之后!)

返回false;}

if(diffDate> 30&& diffDate< 0){alert(" Please please the date in

)范围)

返回false;}

返回true;

}


谢谢,

Vishnu
>
Hi,

I need to write a Javascript which calculates datedifference as well
as date comparision.When i try to embed the below script,it is working
well,but the page is submitting even when the condition evaluates to
false .Please let me know the reason what is the problem in the below
script.
function ValidateDate()
{

var fromDate=new
Date(document.getElementById("txtFromFiledDate").v alue);
var toDate=new
Date(document.getElementById("txtToFiledDate").val ue);
var diffDate=new Date();
diffDate = (toDate - fromDate);
diffDate = ((((diffDate / 1000) / 60) / 60) / 24);
alert("Difference is: " + diffDate);
alert(diffDate>30);
if(diffDate<0){alert("Start Date cannot be after End Date!")
return false;}
if(diffDate>30 && diffDate<0) {alert("Please enter the date in
Range")
return false;}
return true;
}
Thanks,
Vishnu



您好,


您的表格标签看起来如何?

应该如下所示:

< form action =" bla" onSubmit ="返回ValidateDate();">


介意在函数调用之前返回。

如果onSubmit返回false,则表单未提交。

一个常见的错误就是忘记回报(从自己的经验来讲。)


问候,

Erwin Moller

Hi,

How does your formtag look?
It should look like this:
<form action="bla" onSubmit="return ValidateDate();">

mind the return before the functioncall.
If onSubmit returns false, the form is not submitted.
A common mistake is to forget the return (speaking from own experience.)

Regards,
Erwin Moller


嗨Erwin,


感谢您的回复。正如您所说,我忘了指定

在调用函数时返回语句。


谢谢,

Vishnu


Erwin Moller写道:
Hi Erwin,

Thanks for your lightening response.As you said,i forgot to specify
return statement while calling the function.

Thanks,
Vishnu

Erwin Moller wrote:
se****@gmail.com 写道:
se****@gmail.com wrote:





我需要编写一个Javascript来计算日期差异以及

作为日期比较。当我尝试嵌入下面的脚本,它正在工作

,但即使条件评估为

f,该页面仍在提交请告诉我以下

脚本中出现问题的原因。
函数ValidateDate()

{


var fromDate = new

Date(document.getElementById(" txtFromFiledDate")。v alue);

var toDate = new

Date(document.getElementById(" txtToFiledDate")。val ue);

var diffDate = new Date();

diffDate =(toDate - fromDate);

diffDate =((((diffDate / 1000)/ 60)/ 60)/ 24);

alert(" Difference is:" + diffDate);

alert(diffDate> 30);

if(diffDate< 0){alert(开始日期不能在结束日期之后!)

返回false;}

if(diffDate> 30&& diffDate< 0){alert(" Please please the date in

)范围)

返回false;}

返回true;

}

谢谢,

Vishnu

Hi,

I need to write a Javascript which calculates datedifference as well
as date comparision.When i try to embed the below script,it is working
well,but the page is submitting even when the condition evaluates to
false .Please let me know the reason what is the problem in the below
script.
function ValidateDate()
{

var fromDate=new
Date(document.getElementById("txtFromFiledDate").v alue);
var toDate=new
Date(document.getElementById("txtToFiledDate").val ue);
var diffDate=new Date();
diffDate = (toDate - fromDate);
diffDate = ((((diffDate / 1000) / 60) / 60) / 24);
alert("Difference is: " + diffDate);
alert(diffDate>30);
if(diffDate<0){alert("Start Date cannot be after End Date!")
return false;}
if(diffDate>30 && diffDate<0) {alert("Please enter the date in
Range")
return false;}
return true;
}
Thanks,
Vishnu



您好,


您的表格标签看起来如何?

它应该看起来像这样:

< form action =" bla" onSubmit ="返回ValidateDate();">


介意在函数调用之前返回。

如果onSubmit返回false,则表单未提交。

一个常见的错误就是忘记回报(从自己的经验来讲。)


问候,

Erwin Moller


Hi,

How does your formtag look?
It should look like this:
<form action="bla" onSubmit="return ValidateDate();">

mind the return before the functioncall.
If onSubmit returns false, the form is not submitted.
A common mistake is to forget the return (speaking from own experience.)

Regards,
Erwin Moller





现在正面临另一个问题。它告诉脚本错误返回
$函数外的b $ b语句

请让我知道为什么会出现这个错误。


谢谢,

Vishnu
se****@gmail.com 写道:

嗨Erwin,


感谢您的回复。正如您所说,我在调用该函数时忘记指定

返回语句。


谢谢,

Vishnu


Erwin Moller写道:
Hi Erwin,

Thanks for your lightening response.As you said,i forgot to specify
return statement while calling the function.

Thanks,
Vishnu

Erwin Moller wrote:
se **** @ gmail.com 写道:
se****@gmail.com wrote:

>



>

我需要编写一个Javascript来计算日期差异以及

作为日期比较。当我尝试嵌入以下内容时脚本,它正在工作

,但即使条件评估为
false,页面仍在提交。请告诉我下面的问题是什么原因

脚本。

>

>

函数ValidateDate()

{

>

var fromDate = new

Date(document.getElementById(" txtFromFiledDate")。v alue);

var toDate = new

Date(document.getElementById(" txtToFiledDate")。val ue);

var diffDate = new Date();

diffDate =(toDate - fromDate);

diffDate =((((diffDate / 1000)/ 60)/ 60)/ 24);

警报(差异是: " + diffDate);

alert(diffDate> 30);

if(diffDate< 0){alert(开始日期不能在结束日期之后!)

返回false;}

if(diffDate> 30&& diffDate< 0){alert(" Please please the date in

)范围)

返回false;}

返回true;

}

>

>

谢谢,

Vishnu
>
Hi,
>
I need to write a Javascript which calculates datedifference as well
as date comparision.When i try to embed the below script,it is working
well,but the page is submitting even when the condition evaluates to
false .Please let me know the reason what is the problem in the below
script.
>
>
function ValidateDate()
{
>
var fromDate=new
Date(document.getElementById("txtFromFiledDate").v alue);
var toDate=new
Date(document.getElementById("txtToFiledDate").val ue);
var diffDate=new Date();
diffDate = (toDate - fromDate);
diffDate = ((((diffDate / 1000) / 60) / 60) / 24);
alert("Difference is: " + diffDate);
alert(diffDate>30);
if(diffDate<0){alert("Start Date cannot be after End Date!")
return false;}
if(diffDate>30 && diffDate<0) {alert("Please enter the date in
Range")
return false;}
return true;
}
>
>
Thanks,
Vishnu






你的表格标签看起来如何?

看起来应该是这样的:

< form action =" bla" onSubmit ="返回ValidateDate();">


介意在函数调用之前返回。

如果onSubmit返回false,则表单未提交。

一个常见的错误就是忘记回报(从自己的经验来讲。)


问候,

Erwin Moller

Hi,

How does your formtag look?
It should look like this:
<form action="bla" onSubmit="return ValidateDate();">

mind the return before the functioncall.
If onSubmit returns false, the form is not submitted.
A common mistake is to forget the return (speaking from own experience.)

Regards,
Erwin Moller


这篇关于请帮我这个脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆