Click here to Skip to main content
15,894,240 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi
I have two Javascript functions named validatePhone() and validateEmail() and two text boxes named txtPhone and txtEmail and a button submit where to place my script and how to call that

thank you
Posted
Updated 24-May-11 15:55pm
v4
Comments
Sergey Alexandrovich Kryukov 23-May-11 2:41am    
Not clear. You probably mean Javascript?
--SA

I suspect you mean Javascript.
Do you no that Javascript has nothing to do with Java? None of those two languages was derived by another one or even influenced.

Java is not used for scripting, it's totally based on compilation to byte code.

[EDIT 1]
After all those down-votes, I can see someone won't understand until I repeat: the question asks about "java script". There is no such thing! If the question was about Javascript, I want to see exactly this name in the title and body of the question.
If it is Java, I explain that it is something that has nothing to do with Javascript.

[EDIT 2]
If this is not enough, watch this: http://www.youtube.com/watch?v=u9_kahA_wQo[^].

Better now?

[EDIT 3]
Now when the misunderstanding about the scripting language is probably cleared: about position of the script.

There are two places: a script in external file (let's place it in "scripts/mylib.js") and embedded in HTML. Let me show both cases below:

HTML
<html>
   <head>
      <title>My title</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <script type="text/javascript" src="./scripts/mylib.js" />
      <script type="text/javascript"><!--
         //Javascript functions go here
      --></script>
   </head>
<body>

<!-- page content here -->

</body>
</html>


—SA
 
Share this answer
 
v4
Comments
Ashishmau 23-May-11 2:48am    
howcome u noticed java from his question. Read his question carefully...
Sergey Alexandrovich Kryukov 23-May-11 3:10am    
PLEASE READ CAREFULLY BEFORE DOWN-VOTING!
Read the title of the question. "Java script" is NOT "Javascript", OK?
And don't tell me it is a typo!
--SA
PRASAD GDV 24-May-11 3:07am    
i really apologize for that i know difference between java and javascript. i changed my question


vara prasad
Sergey Alexandrovich Kryukov 24-May-11 3:18am    
Thank you very much (but I don't see the change in your question).
Now, please see the answer to your question about placing the script.
Do you have further (follow-up) questions?
--SA
<script language=:javascript&quot; type=&quot;text/javascript&quot;&gt;
function validate()
{
if (document.getElementById(&quot;&lt;%=txt_id.ClientID%&gt;&quot;).value == &quot;&quot;)
{
alert(&quot;User Id Feild can not be blank&quot;);
document.getElementById(&quot;&lt;%=txt_id.ClientID%&gt;&quot;).focus();
return false;
}
if (document.getElementById(&quot;&lt;%=txtfname.ClientID%&gt;&quot;).value == &quot;&quot;)
{
alert(&quot;First Name Feild can not be blank&quot;);
document.getElementById(&quot;&lt;%=txtfname.ClientID%&gt;&quot;).focus();
return false;
}
if (document.getElementById(&quot;&lt;%=txtlname.ClientID%&gt;&quot;).value == &quot;&quot;) {
alert(&quot;Last Name Feild can not be blank&quot;);
document.getElementById(&quot;&lt;%=txtlname.ClientID%&gt;&quot;).focus();
return false;
}
if (document.getElementById(&quot;&lt;%=txtemail.ClientID %&gt;&quot;).value == &quot;&quot;)
{
alert(&quot;Email address can not be blank&quot;);
document.getElementById(&quot;&lt;%=txtemail.ClientID %&gt;&quot;).focus();
return false;
}
var emailPat = /^(\&quot;.*\&quot;|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid = document.getElementById(&quot;&lt;%=txtemail.ClientID %&gt;&quot;).value;
var matchArray = emailid.match(emailPat);
if (matchArray == null) {
alert(&quot;Your email address seems incorrect. Please try again.&quot;);
document.getElementById(&quot;&lt;%=txtemail.ClientID %&gt;&quot;).focus();
return false;
}
if (document.getElementById(&quot;&lt;%=txtuname.ClientID%&gt;&quot;).value == &quot;&quot;)
{
alert(&quot;Username can not be blank&quot;);
document.getElementById(&quot;&lt;%=txtuname.ClientID%&gt;&quot;).focus();
return false;
}
if (document.getElementById(&quot;&lt;%=txtpass.ClientID%&gt;&quot;).value == &quot;&quot;)
{
alert(&quot;Password can not be blank&quot;);
document.getElementById(&quot;&lt;%=txtpass.ClientID%&gt;&quot;).focus();
return false;
}
var digits = &quot;0123456789&quot;;
var temp;
for (var i = 0; i &lt; document.getElementById(&quot;&lt;%=txt_id.ClientID%&gt;&quot;).value.length; i++)
{
temp = document.getElementById(&quot;&lt;%=txt_id.ClientID%&gt;&quot;).value.substring(i, i + 1);
if (digits.indexOf(temp) == -1)
{
alert(&quot;Please enter valid Id&quot;);
document.getElementById(&quot;&lt;%=txt_id.ClientID%&gt;&quot;).focus();
return false;
}
}
var digits = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ &quot;;
var temp;
for (var i = 0; i &lt; document.getElementById(&quot;&lt;%=txtfname.ClientID%&gt;&quot;).value.length; i++) {
temp = document.getElementById(&quot;&lt;%=txtfname.ClientID%&gt;&quot;).value.substring(i, i + 1);
if (digits.indexOf(temp) == -1) {
alert(&quot;Please enter character only...&quot;);
document.getElementById(&quot;&lt;%=txtfname.ClientID%&gt;&quot;).focus();
return false;
}
}
var digits = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ &quot;;
var temp;
for (var i = 0; i &lt; document.getElementById(&quot;&lt;%=txtlname.ClientID%&gt;&quot;).value.length; i++) {
temp = document.getElementById(&quot;&lt;%=txtlname.ClientID%&gt;&quot;).value.substring(i, i + 1);
if (digits.indexOf(temp) == -1) {
alert(&quot;Please enter character only...&quot;);
document.getElementById(&quot;&lt;%=txtlname.ClientID%&gt;&quot;).focus();
return false;
}
}
return true;
}
</script>
 
Share this answer
 
U can call javascript function on button OnClientClick event and return false if validation fails.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900