Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Alert Msg question...

Status
Not open for further replies.

edge27

Programmer
Jun 23, 2003
12
0
0
US
Hi,

I created a javascript validation in .net for the user to receive an alert if they entered an invalid date. The user gets the msg, but the code behind continues and redirects them to the new page trying to use an invalid date. Should the alert have stopped the processing or is their something I need to do?

Thanks,

The Edge
 
The alert by itself will not stop the code from continuing... you need to do that yourself. Usually you would be in a function, and you might return false to let the calling function know what is happening.

If you post the "view source" equivalent of the javascript (with details of how you call it), I'm sure we'll be able to give you all kinds of insight [smile]

Jeff


[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Thanks...I am using "return false"...here is the javascript:

if (window.Form1.txtDateFrom.value !== "")
if (window.Form1.txtDateFrom.value !== "")
{
var dt=window.Form1.txtDateFrom

if (isDate(dt.value)==false){
dt.focus()
return false
}
}
 
where is the alert?

Try this:

Code:
var dateField = document.forms['Form1'].elements['txtDateForm'];
if ( dateField.value == '' || !isDate(dateField.value) ) {
    alert('enter a valid date');
    dateField.focus();
    return false;
}

and call it like this:

Code:
<form ... onsubmit="return myFuncName();">

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Sorry...I have the alert in the isDate function. I will see if you suggestion is apropo tomorrow, cLFlaVA, when Im in the office. Thanks
 
So, how did you get on with that then, edge27?

In response to your duplicate thread... from your initial post:
Should the alert have stopped the processing or is their something I need to do?
And my initial reply:
The alert by itself will not stop the code from continuing... you need to do that yourself.
It would seem that you haven't really made much of an attempt to solve this problem yourself... maybe I'm not reading the situation properly.

As I said... let us know how you got on.

Cheers,
Jeff


[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top