java script

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sunilgupta
Forum Newbie
Posts: 1
Joined: Sat Nov 14, 2009 7:57 am

java script

Post by sunilgupta »

<script language = "Javascript">

function Validate()
{
if (document.registration_form.name.value == '')
{
alert('Please fill in your name!');
return false;
}
if (document.registration_form.email.value == '')
{
alert('Please fill in your email address!');
return false;
}
if (document.registration_form.username.value == '')
{
alert('Please fill in your desired username!');
return false;
}
if (document.registration_form.password.value == '')
{
alert('Please fill in your desired password!');
return false;
}
if (document.registration_form.password_confirmation.value == '')
{
alert('Please fill in your password again for confirmation!');
return false;
}
if (document.registration_form.password.value !=
document.registration_form.password_confirmation.value)
{
alert("The two passwords are not identical! "+
"Please enter the same password again for confirmation");
return false;
}
if (document.registration_form.phone_number.value == '')
{
alert('Please fill in your phone number!');
return false;
}
return true;
}
</script>

Include this piece of code on your page, and change the <form> tag to trigger the execution of the Validate() function on form submit:

<form name="registration_form" method="post" action="register.php
onsubmit="return Validate();"



i am beginner in php, when i am calling above given alert script in php code it does not work between us,Please give me solution how it will work well.

Looking forward for your reply soon.

Thanks!

Regards
Sunil Gupta
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: java script

Post by iankent »

Probably a javascript error - get Firebug (if you're using Firefox) or Firebug Lite for other browsers. Alternatively use Opera and the javascript backtracing. Should identify any errors pretty quickly.

Also, please use [syntax=php]tags, makes your code easier to read[/syntax]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: java script

Post by superdezign »

Shouldn't you be using the ID attribute instead of the name attribute...?

Also, make sure you perform validation on the server-side as well.
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: java script

Post by iankent »

superdezign wrote:Shouldn't you be using the ID attribute instead of the name attribute...?
afaik when referring to a named form object with a named form element, the method used by the OP is acceptable as the named elements become objects, i.e. document.myform.myinput
Post Reply