aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Resetting a Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Resetting a Form" Watch "Resetting a Form" New topic
Author

Resetting a Form

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 20, 2009
Posts: 44
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


Thanks And Regards
Goutam Chowdhury (Scjp1.4 86%,SCWCD5 94%)
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
@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

Joined: Nov 08, 2001
Posts: 15376
    
    6
What is up with the undefined checks?

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Resetting a Form