Click here to Skip to main content
15,889,826 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi dears
i wrote below html code:
HTML
<body>
<div id="registration">
 <h2 style"background-color: #000000">فرم حساب کاربری</h2>

 <form id="RegisterUserForm" action=""  name="RegisterUserForm" onsubmit="">
 	<fieldset>
         <p>
             <label for="name">نام </label>
            <input id="name" name="name" type="text" class="text" value="" />
         </p>


          <p>
          <label for="name">فامیلی</label>
            <input id="name1" name="name1" type="text" class="text" value="" />
         </p>
          <p>
          <label for="tel">شماره تلفن</label>
            <input id="tel" name="tel" type="tel" class="text" value="" />
         </p>

         <p>
            <label for="email">ایمیل</label>
            <input id="email" name="email" type="email" class="text" value="" />
         </p>
          <p>
          <label for="name">نام کاربری</label>
            <input id="username" name="username" type="text" class="text" value="" />
         </p>
         <p>
         <label for="password">رمز عبور</label>
            <input id="password" name="password" class="text" type="password" />
         </p>
           <p>
           <label for="password">تکرار رمز عبور</label>
            <input id="password2" name="password2" class="text" type="password" />
         </p>

         <p><input id="acceptTerms" name="acceptTerms" type="checkbox" />
            <label for="acceptTerms">
               اینجانب <a href="">شرایط و قوانین</a> این سایت را کاملا مطالعه نموده ام و قبول دارم
            </label>
         </p>

         <p>
            <button id="registerNew" type="submit"  onclick="validateForm(),checkpassword()">ثیت نام</button>
         </p>
 	</fieldset>

 </form>
</div>


</body>

and this java code for validation:
Java
<script type="text/javascript">
  function validateForm()
{
var name=document.forms["RegisterUserForm"]["name"].value;
var family=document.forms["RegisterUserForm"]["tel"].value;
var email=document.forms["RegisterUserForm"]["email"].value;
var tell=document.forms["RegisterUserForm"]["password"].value;


if (name==null || name==""||family==null || family==""||email==null || email==""||password==null || password=="")
  {
   alert("تمامي فيلدها بايد پر شود");
   var a="تمامي فيلدها بايد پر شود";

  }
}
function checkpassword()
{
var name=document.forms["RegisterUserForm"]["password"].value;
var tell=document.forms["RegisterUserForm"]["password2"].value;


if (name!=tell)
  {
   alert("لطفا رمز عبور يکسان وارد کنيد");
  return false;
document.forms["RegisterUserForm"]["name"].value="";
document.forms["RegisterUserForm"]["password"].value=""
  }
}
 </script>

in html file it's worked but when i copy in asp.net dont worked
Posted
Updated 18-Apr-12 22:11pm
v2
Comments
Sandeep Mewara 19-Apr-12 4:37am    
You have to be clear on what did not work and what was the error/behaviour? Did you try to DEBUG and see the execution?
Prasad_Kulkarni 19-Apr-12 4:55am    
What's error you're getting??
Mohamed Mitwalli 19-Apr-12 6:50am    
Why you are not using Validate controls ????
Dhanushka Madushan lk 20-Apr-12 5:41am    
check this
http://www.codeproject.com/Articles/367001/Introduction-to-ASP-NET-validation

First error that I see just from the code is in your last if block.

JavaScript
if (name!=tell)
  {
   alert("لطفا رمز عبور يکسان وارد کنيد");
  
document.forms["RegisterUserForm"]["name"].value="";
document.forms["RegisterUserForm"]["password"].value="" // you need to end the statement.
return false; // first assign your fields and then return when you are done.
  }
}
 
Share this answer
 
Just Use Asp.Net Validators..Those are much more useful than java script. Working on asp.net & why not using asp.net validators, you will just have to put those in front of the text Box
Thanks.
 
Share this answer
 
thanks for ur answers,
i find the problem,
just this code :
ASP.NET
<form id="Form1"  runat="server">

have good time.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Jun-16 18:59pm    
Sorry, this is not an answer or "solution". Such posts are considered as abuse. Instead, you need to update your questions using "Improve question"; in other cases, you can use comments.
—SA

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