JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 8th, 2003, 04:58 PM
hatter hatter is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 hatter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
form name problem

Hello

I have a script which validates form fields and uses:

<form name="Sample1" method="post">

Once I have completely the form fields correctly (if I don't I get an error message in red), and click the Submit button, the page doesn't lead anywhere (I don't have a redirect on the page).

On the other hand, if I remove the abover and substutite this:

<form name="thanks" method="POST" action="thanks.asp">

and click the Submit button, it does take me to the "thank you" page, BUT DOES NOT VALIDATE THE FIELDS.

How can I combine the two?

Many thanks for any advice.

Hatter

Reply With Quote
  #2  
Old September 8th, 2003, 05:20 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
javascipt validation

use javascript for validation and use the onSubmit event handler in your form.

This eventhandler will be executed before the page changes.

Small example:
Code:
<script language="JavaScript" type="text/javascript">
function FormValidation(oForm) {
   if (oForm.textfield.value.length == 0 ) {
     alert ("please enter a value");
     oForm.textfield.focus();
     return false; }
}
</script>
<form action="handleForm.asp" method="post" 
onSubmit="javascript: return FormValidation(this)" 
name="myForm">
<input type="text" name="textfield">
<input type="submit" name="cmdSubmit" value="submit">
</form>


for more help on validating fields using javascipt, please post questions in the javascript forum.

Hope this helps,
__________________
- Rogier Doekes

Reply With Quote
  #3  
Old September 9th, 2003, 06:58 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
In your first snippet, you didn't give the form an action. In the second, it has an action but not the same name as in the first snippet. My guess is that your validation script cares that the form is named and so won't work when you use the second snippet. But since the first snippet has no action parameter, there's nothing for it to do. Just add the action parameter to your first snippet and I suspect you'll be good to go.

Reply With Quote
  #4  
Old September 9th, 2003, 07:45 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Following on from what dhouston has said, creating modular validation scripts is made easier if you don't use specific form names. (To accomplish this, keep your JS validation code in an external *.js file, and link it using src="blah.js") To pass the form object as a parameter, do something like this:
Code:
<script language="Javascript" type="text/javascript">
function validate(theForm) {
  varFname = theForm.fname.value
  if (varFname == "") {
    //err...
  }
}
</script>
<form name="frmRego" action="reg.asp" method="post" onSubmit="return validate(this)">
  <input type="text" name="fname">
</form>

Reply With Quote
  #5  
Old September 9th, 2003, 08:12 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Yeah, stumpy's definitely onto something. A while back, I actually wrote a portable and pretty much all-purpose validation js that I can use with any page. I include it at the top of the needed files as stumpy proposes above. Then, above my form, I write a little inline js that defines an array of field names, types, and error messages. I pass these along with the form itself to my js onsubmit, and the script does the appropriate validation based on the form type and returns the appropriate error message, etc. The more general the validation code the better.

Reply With Quote
  #6  
Old September 9th, 2003, 08:25 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
I once saw a very groovy bit of JS very similar to what dhouston is talking about, a few years ago. It stored all the checking info (check type [range checking, etc], error message, data types, etc) in hidden fields - almost exactly like how .NET works now.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > form name problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT