Re: Please help me how to call this Javascript

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Show us more code (espacially text boxes declaration)
--
Milosz Skalecki
MCP, MCAD


"settyv@xxxxxxxxx" wrote:

Hi,

It is not working .it is telling script error.Here is the HTML created
after the postback.Everything is fine.But i dont know why it is telling
error.

Microsoft JScript runtime error: 'document.GetElementById.txtFromDate'
is null or not an object

<TR vAlign="top">
<TD colSpan="4" height="25"></TD>
<TD><input type="submit" name="btnSubmit" value="Submit"
id="btnSubmit" onClick="return
ValidateDate(document.getElementById["txtFromDate"].Value,document.getElementById["txtToDate"].Value);"
/></TD>
</TR>

Please let me know how can i solve this.


Thanks,
Vishnu

rampabbaraju@xxxxxxxxx wrote:
Try this

btnSubmit.Attributes.Add("onClick"," return
ValidateDate(document.GetElementById('" +
txtFromDate.ClentId() + ').Value",document.GetElementById('" +
txtToDate.ClentId()+ "'));");



settyv@xxxxxxxxx wrote:
Hi,

Below is the Javascript function that am trying to call from asp:Button
control.

<script language="javascript">
function ValidateDate(fromDate,toDate)
{

var fromDate=new Date();
var toDate=new Date();
var diffDate = Math.round( ( toDate-fromDate ) / 864e5 );
alert(diffDate);
if( diffDate < 0 )
{
alert( "The start date cannot be after the end date!")
return false;
}

if( diffDate > 30 )
{
alert( "Please enter dates less than 31 days apart" )
return false;
}

return true; //allow submit
}
</script>


In code-behind am calling the function like as below:
btnSubmit.Attributes.Add("onClick"," return ValidateDate(" +
txtFromDate.Text.ToString() + "," + txtToDate.Text.ToString() + ");");



But if start entering the dates,it submits the page as it takes both
datee as current dates.Please let me know the reason.

Thanks,
Vishnu


.



Relevant Pages

  • Re: Please help me how to call this Javascript
    ... var fromDate = new Date; ... var toDate = new Date; ... if(diffDate < 0) ... alert("The start date cannot be after the end date!"); ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Please help me how to call this Javascript
    ... Microsoft JScript runtime error: 'document.GetElementById.txtFromDate' ... var fromDate=new Date; ... if(diffDate < 0) ... alert("The start date cannot be after the end date!") ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Please help me how to call this Javascript
    ... And am trying to call the javascript that i sent earlier in code-behind ... Now the problem is that am not able to see alert msg saying that the ... var fromDate=new Date; ... if(diffDate < 0) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Please help me how to call this Javascript
    ... control. ... var fromDate=new Date; ... if(diffDate < 0) ... alert("The start date cannot be after the end date!") ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: OnClick and onSubmit
    ... Prototype.js was written by people who don't know javascript for people ... function validatePwd() { ... var pw2 = document.Acct.Password2.value; ... alert ("You did not enter the same new password twice. ...
    (comp.lang.javascript)