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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello I have some JavaScript and

Status
Not open for further replies.

LaPluma

Programmer
Feb 3, 2002
139
DE
Hello

I have some JavaScript and ASP code which I can't get to work. The Javascript validates e.mail addresses, and a piece of asp code a valid e.mail address to a database. Both the JavaScript and asp code work independently, so why can't I put them together in an .htm file like this:

<HTML>
<HEAD>


<script language=&quot;javascript&quot; runat=&quot;server&quot;>
function ValidEmail(EmailAddr){
if(EmailAddr){
var vemail = /^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
var EmailTest = (vemail.test(EmailAddr));
return EmailTest;
}
}
</script>


<% 'Example of how to use it...
Dim Email, EmailGood
Email = Request.Form(&quot;Email&quot;)
EmailGood = ValidEmail(Email)
%>

<TITLE>mail</TITLE></HEAD>
<BODY>

<center><h3>XXXX<font color=&quot;#000099&quot;>YYYY</font></h3></center>

<form action=&quot;mail_ac.asp&quot; method=&quot;post&quot;>


<center><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000099&quot;><font size=-1>Email</font></font></font></b>


<input type=&quot;text&quot; name=&quot;Email&quot; cols=&quot;60&quot;>

<p><input type=&quot;submit&quot; value=&quot;Submit&quot;></p></center>

</form>
</BODY>
</HTML>


Any comments are welcome
 
hi,
As far as my knowledge is considered u can call javascript function on events like onclick ,onchange etc....

why dont u write the same function in asp using
sub functionname
....
....
end

 
You could reqriute the javascript to run client side and call it from the form tag with

Code:
<form action=&quot;mail_ac.asp&quot; method=&quot;post&quot; onSubmit=&quot;return ValidEmail(this.Email.value);&quot;>

this will validate client side and then if it fails the form won't submit, if itruns the form will submit. One thing you didn't mention is if this form is submitting back to the same page. If it isn't then the ASP only runs before the form is ever displayed to the user(server-side). Also, I haven't found a good way to force a VBScript (default ASP language) to call a server-side javascript. You may run into some issues there since the ASP is formulating the page by running only ASP scripts (may be wrong, VBScript calling Javascript was a pet project a long time ago).

If you absolutely must check the addres server-side, I would check on the page the form is submitting to and choose one language to use.

-Tarwn
My hats to tight...oh...no...nevermind, i guess my heads just to big :p
 
Hi,
what u said is exactly correct.Why dont you validate it on the first page itself.I never did validation on second page.
If it is wrong email id u can ask for correct one in the first page itself .Could i know why r u validating on second page?.Is there any perticular reason?
 
Hello

Thank you all for your intelligent feedback.

The page is here:


The code behind it includes the JavaScript which should validate the e.mail address. In fact, I have tried it with some other JavaScript (below) aimed at validating the e.mail address and that doesn't work either.

Basically, there's nothing wrong with the JavaScript - but I just wanted to check it out.

No, Ramnagar, there is no particular reason for not wanting to validate it on the same page, except that I'm unsure how to do it!

I ave also tried the following, but it doesn't seem to work either:

<HEAD>
<script language=&quot;JavaScript&quot;>
function emailvalidation()
{
str = document.myfrm.email.value;
idxAt = str.indexOf(&quot;@&quot;);
idxDot = str.indexOf(&quot;.&quot;);
idxLast = str.length - 1;
if((idxAt) < 1 || (idxDot - idxAt < 2) || (idxLast - idxDot > 3) || (idxLast - idxDot < 2))
{
return false
}
return true;
}
</script>
</HEAD>
<BODY>
<form action=&quot;mail_ac.asp&quot; method=&quot;post&quot; onSubmit=&quot;return ValidEmail(this.Email.value);&quot;>
</BODY>

Anyway, thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top