Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resetting a Form

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I was trying to create a form where when the user submits the requests with some incomplete fields, the page should show an error about which field is missing within that same webpage and not submit the request and all the fields should be cleared of what was entered by the user. But the problem is that I am successfully able to clear the fields, But the page is still going ahead and posting the request which i don't want. Could please take a look at my code and tell me what's wrong here!

Here's a fragment of the JavaScript (I am not posting the whole thing as it is quite lengthy!)




The function is being called like:


Could anyone suggest how to prevent the form from submitting the request?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are setting pEmail to undefined and than you are trying to use the object to focus it.

Why would you reset the entire form on an error? You really want to punish your users?

Eric
 
Goutam Chowdhury
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Your code is not good ,but whatever I should run fine.
As per my understanding Problem is

1.Check your browser support script or not,I mean to say that put alert in the function and check it is coming or not.
1.Check with FF.
2.For IE,If it ask you to allow ActiveX then do the same....


For me its working
And one more thing
Check my code
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Eric: I agree! But that is not my requirement! My client wants it that way! I raised this issue with them and they said that is how they would like it! somehow when i was told this, i found it quite silly!

Well i got my code working! All i did was modify the function:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is up with the undefined checks?

 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like if the user enters two of the values out of the three, then one of the would be "undefined" right? That's why the check.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64964
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. It will be blank. What made you think it would be undefined? It's easy enough to test for such things before you make assumptions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic