Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Validate form

View previous topic View next topic Go down 
AuthorMessage
UsernameChange
Staff
Staff
avatar

Posts : 16
Join date : 2011-03-09

Validate form  Empty
PostSubject: Validate form    Validate form  EmptyFri Mar 25, 2011 6:45 am

Hi!

Im trying to lern how to use JavaScript in my homepage.

Im trying to make an alert box come up if a person did not fill in the name of a form like this:

The HTML:
Code:

<form method="POST" name="myform" action="http://formfixer.com/ff/ff.cgi" onSubmit="return validateForm();"> 
 
  <input type="hidden" name="s_email" value="koanuka@capoeiras.se">
  <input type="hidden" name="s_retur" value="http://www.koanuka.se/mah/registrering.html">

<p>Ditt namn:</p>

<p> <input type="text" size="20" name="namn"> </p>

<p>Din e-postadress:</p>

<p> <input type="text" size="20" name="email"> </p>

    <input type="submit" value="Skicka">

</p>

</form>

The JavaScript:
Code:

function validateForm() { 
 var name = document.myForm.username.value; 
 if (name == "") { 
  alert("Required field not filled in!"); 
  return false; 
 } else return true; 
}
My question is how do I "connect" the form to the JavaScript? I have a: <script type="text/javascript" src="myscript.js"> in the head of the html. But do I need to use "getElementById"?

Thankful for a pedagogical answer
Back to top Go down
Wishes
Member
Member
Wishes

Posts : 9
Join date : 2011-04-16

Validate form  Empty
PostSubject: Re: Validate form    Validate form  EmptySat Apr 16, 2011 8:10 pm

I have no idea im just a begginer
Back to top Go down
 

Validate form

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» asp.net form
» form validation of a checkbox not quite right
» <div> refresh after form submission - a bug
» AutoFilling an edit form using C#.NET and SQL
» Ajax/jQuery Form $_POST and use PHP?

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Validate form  Edit-trash Useless :: Trash-