Hi,

This is the code for form validation to check whether the username has six characters.i'm getting error.In form element i have added action="registration.aspx" i think it is for validaiton in server.. wat is the purpose of it???

can anyone pls suggest free links for webdeveloping ebooks using javascript?. how jquery is related to javascript? How to build online buying websites???

<!DOcTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>first java script example</title>
<meta http-equiv="content-type"  content="text/html; charset=ISO-8859-1" />

<script type="text/javascript">

function validate(form)
{
var returnValue=true;
var username=frmRegister.txtUserName.value;
var password1=frmRegister.txtPassword1.value;
var password2=frmRegister.txtPassword2.value;
if(username.length < 6)
{
returnValue=false;
alert("your username must be atelast six characters");
frmRegister.txtUserName.focus();
}
return returnValue;
</script>

<body>
<form name="frmRegister" method="post" action="register.aspx" onsubmit="return validate(this);">

<div class="label"><label for="txtUsername">username:</label></div>
<div class="formElement">
<input type="text" name="txtUsername" id="txtUserName" size="12" />

</div>

<div class="label"><label for="txtPassword">password:</td></label></div>
<div class="formElement">
<input type="password" name="txtUserName id="txtPassword" size="12" />
</div>
<div class="formElement"><input type="submit" value="login" /></div>
</form>
</body>
</html>

thanks for ur time

1]
You are getting errors in validation because there are syntax errors in the code snippet.
Be careful to close brackets and quotation marks in the code.
There is '}' missing after 'return returnValue;' in the javascript function.
Also in the line

<input type="password" name="txtUserName id="txtPassword" size="12" />

" missing after txtUserName

Further you have not change the name for the password input field. It is still txtUserName but should be txtPassword because the value in the 'name' attribute is used in javascript and at the serverside

The code should be something like

<!DOcTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>first java script example</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />

<script type="text/javascript">

function validate(form)
{
var returnValue=true;
var username=frmRegister.txtUserName.value;
var password1=frmRegister.txtPassword.value;

if(username.length < 6)
{
returnValue=false;
alert("your username must be atelast six characters");
frmRegister.txtUserName.focus();
}
return returnValue;
}
</script>

<body>
<form name="frmRegister" method="post" action="register.aspx" onsubmit="return validate(this);">

<div class="label"><label for="txtUsername">username:</label></div>
<div class="formElement">
<input type="text" name="txtUsername" id="txtUserName" size="12" />

</div>

<div class="label"><label for="txtPassword">password:</td></label></div>
<div class="formElement">
<input type="password" name="txtPassword" id="txtPassword" size="12" />
</div>
<div class="formElement"><input type="submit" value="login" /></div>
</form>
</body>
</html>

2]
action="registration.aspx"

is used to indicate the page where the control will go when the form is submitted. In this case it is a page called 'registration.aspx'. It can contain server side validations as well as business logic like database talks and control flows.

3]
There are numerous online resources for web development. You can find some useful resources at
http://mashable.com/2010/02/03/web-development-resources/

4]
jQuery is a javascript library designed to simplify document traversing, AJAX support and some cool animation effects


Hope this was helpful

1]
You are getting errors in validation because there are syntax errors in the code snippet.
Be careful to close brackets and quotation marks in the code.
There is '}' missing after 'return returnValue;' in the javascript function.
Also in the line

<input type="password" name="txtUserName id="txtPassword" size="12" />

" missing after txtUserName

Further you have not change the name for the password input field. It is still txtUserName but should be txtPassword because the value in the 'name' attribute is used in javascript and at the serverside

The code should be something like

<!DOcTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>first java script example</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />

<script type="text/javascript">

function validate(form)
{
var returnValue=true;
var username=frmRegister.txtUserName.value;
var password1=frmRegister.txtPassword.value;

if(username.length < 6)
{
returnValue=false;
alert("your username must be atelast six characters");
frmRegister.txtUserName.focus();
}
return returnValue;
}
</script>

<body>
<form name="frmRegister" method="post" action="register.aspx" onsubmit="return validate(this);">

<div class="label"><label for="txtUsername">username:</label></div>
<div class="formElement">
<input type="text" name="txtUsername" id="txtUserName" size="12" />

</div>

<div class="label"><label for="txtPassword">password:</td></label></div>
<div class="formElement">
<input type="password" name="txtPassword" id="txtPassword" size="12" />
</div>
<div class="formElement"><input type="submit" value="login" /></div>
</form>
</body>
</html>

2]
action="registration.aspx"

is used to indicate the page where the control will go when the form is submitted. In this case it is a page called 'registration.aspx'. It can contain server side validations as well as business logic like database talks and control flows.

3]
There are numerous online resources for web development. You can find some useful resources at
http://mashable.com/2010/02/03/web-development-resources/

4]
jQuery is a javascript library designed to simplify document traversing, AJAX support and some cool animation effects


Hope this was helpful

hi,

thanks for ur time...

i able to understand but in the form element in action method "registration.aspx" is specified when i'm running the script it say i couldn't find the file "registraiton.aspx"

i'm the beginner in javascript can u pls suggest me good links to reate a website

can u pls get me a link for javascript:the complete reference(powell and schneider) free ebook download...?

The error that the file 'registration.aspx' is not found could be because the file is not present in the proper location on the web server.

Some good online resources on javascript are,
http://www.w3schools.com/js/js_intro.asp
http://www.htmlgoodies.com/beyond/javascript/
http://www.javascriptkit.com/javatutors/primer1.shtml

I am also not sure if there is any legitimate site that offers free download of the ebook - Javascript : Complete Reference

The error that the file 'registration.aspx' is not found could be because the file is not present in the proper location on the web server.

Some good online resources on javascript are,
http://www.w3schools.com/js/js_intro.asp
http://www.htmlgoodies.com/beyond/javascript/
http://www.javascriptkit.com/javatutors/primer1.shtml

I am also not sure if there is any legitimate site that offers free download of the ebook - Javascript : Complete Reference

hi,

thanks for link...

action method is used to handle the even when onsubmit in the server side...

how should i create that file?? registration.aspx?? it is a notepad file?? i can understand wat the action method is for?? but i am unable to get the idea how to handle that??? .how to link the registraion.aspx fiel with this coding??

my objective for this coding is, i want to check whther the username consists 6 characters.. on that basis what should be the contents in registraition .aspx file.

registration.aspx is a ASP.net file. I do not have much idea about .net Framework so cant help on how to handle the data at the server end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.