5 Replies - 598 Views - Last Post: 02 March 2009 - 11:03 AM

#1 kill99  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 03-May 08

Validating the form

Post icon  Posted 01 March 2009 - 04:52 PM


<html>

<head>
<script LANGUAGE="Javascript">

function doSumbit (){

if (!document.forms.firstname.value){
alert("You need to key in your first name");
document.forms.firstname.focus();
return false;}

if (!document.forms.lastname.value){
alert("You need to key in your last name");
document.forms.lastname.focus();
return false;}

if (!document.forms.email.value){
alert("You need to key in your email address");
document.forms.email.focus();
return false;}

if (!document.forms.comments.value){
alert("You need to key in your comments on the site");
document.forms.comments.focus();
return false;}

//forms.action="'mailto:empiresdeath@gmail.com?subject=form comments'";
//document.forms.submit();
alert("Thanks you for filling up the form");
</SCRIPT>

</head>


<body>


<h1>Leave a Comment to the Site</h1>

<form name="forms">
First name: 
<input type="text" name="firstname" size="20">
<br>
Last name:
<input type="text" name="lastname" size="20">
<br>
Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="email" size="20">
<br>
<input type="radio" name="sex" value="male"> Male

<input type="radio" name="sex" value="female"> Female


<div class="alignCenter">
<label class="alignTopLeft" for="comments">
<strong>Comments</strong>
</label>
</div>
<div class="alignCenter">
<textarea name="comments" id="comments" rows="5" cols="30">
</textarea>
</div>

<br><br>
<input type="submit" value="Submit" onclick="doSubmit ()">
<input type="reset" value="clear">


</form>

</body>




</html>




Anyone can help helping problem running the script to work

Is This A Good Question/Topic? 0
  • +

Replies To: Validating the form

#2 OrganizedChaos  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 153
  • Joined: 29-November 08

Re: Validating the form

Posted 01 March 2009 - 06:47 PM

Spelling the function name correctly usually helps.
function doSumbit (){
...
onclick="doSubmit ()"


This post has been edited by OrganizedChaos: 01 March 2009 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 kill99  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 03-May 08

Re: Validating the form

Posted 02 March 2009 - 02:44 AM

View PostOrganizedChaos, on 1 Mar, 2009 - 05:47 PM, said:

Spelling the function name correctly usually helps.
function doSumbit (){
...
onclick="doSubmit ()"




hmm don't thing is spelling mistake still unable to validate the fields

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Validating the form

Posted 02 March 2009 - 03:29 AM

Firstly, you still have a spelling mistake in your function name. It should be doSubmit, not doSumbit.

Next, you are referring to your form incorrectly. All the forms on a page are part of a collection called 'forms'. Your form, which you have also called forms, is part of that collection and so should be referred to like this:

document.forms['forms']



Which makes your code look like this:

function doSubmit(){

if (!document.forms['forms'].firstname.value){
alert("You need to key in your first name");
document.forms['forms'].firstname.focus();
return false;}

if (!document.forms['forms'].lastname.value){
alert("You need to key in your last name");
document.forms['forms'].lastname.focus();
return false;}

if (!document.forms['forms'].email.value){
alert("You need to key in your email address");
document.forms['forms'].email.focus();
return false;}

if (!document.forms['forms'].comments.value){
alert("You need to key in your comments on the site");
document.forms['forms'].comments.focus();
return false;}

//forms.action="'mailto:empiresdeath@gmail.com?subject=form comments'";
//document.forms.submit();
alert("Thanks you for filling up the form");
}


Was This Post Helpful? 1
  • +
  • -

#5 kill99  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 03-May 08

Re: Validating the form

Posted 02 March 2009 - 07:42 AM

hmm thx for the help now i got another problem i know that below cope open a new window but how to code it in a sense that when the new window open it will prompt out a alert msg like " thanks you for filling up the form"

and also the above code how do i retain the information when i type as in when i key in the first name afterwards when i click on the submit button it will validate the other field for other information to be input once click ok on the alert message the first field information will not be wipe out


<form target="_blank"

Was This Post Helpful? 0
  • +
  • -

#6 kiwi2  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 178
  • Joined: 16-September 08

Re: Validating the form

Posted 02 March 2009 - 11:03 AM

add a function to your code to send an alert msg on window.location
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1