wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes problem with jsp for reset() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem with jsp for reset() method" Watch "problem with jsp for reset() method" New topic
Author

problem with jsp for reset() method

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
in my application...i had a modify page...im facing problem with reset() function...here is my code...can anyone provide me the solution

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

im facing problem with reset() function

Which problem ? Can you explain your problem clearly ?


[My Blog]
All roads lead to JavaRanch
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
if i want to clear my form..it is not get cleared..'clear' button is not working...i had posted my jsp page...can you once check it..and provide me where i went wrong..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

the "reset" input does not clear text fields. It resets them to their original value.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9915
    
158

By the way, this looks like the same question as the other one you asked here http://www.coderanch.com/t/504642/HTML-JavaScript/reset-function

[My Blog] [JavaRanch Journal]
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
yes..it is related to jsp..so i posted in jsp forum..it contains javascript also..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

//way 1 if your button type is reset
[code]
<Script>
function clearFields(){
document.getElementById("t1").value="";
return false;
}
</Script>
<form>
<input type=text id="t1" value=Hello><br>
<input type=reset onClick="return a=clearFields()">
</form>


//way 2 if your button type is simple button

<Script>
function clearFields(){
document.getElementById("t1").value="";
}
</Script>
<form>
<input type=text id="t1" value=Hello><br>
<input type=button value="reset" onClick="clearFields()">
</form>

[code]


Swastik
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i tried what you had given in Way2...it is not working....i got why it is not working...i had doubt that i had text fields,combo boxes, check boxes and textarea in my form..for clear of form in javascript for clear..i need to mention all id's or just simple the form name is enough...i tried using form id for clear of my form fields...here is the code..



<input type="reset" value="clear" onClick="clearFields()">

can you check it once...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

This wont work, because value is applicable to a component like text field, password field etc, not to the form.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
kk..i changed it to



eventhough it is not working...can you tell me inorder to clear the form which had default values is not possible am i right..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6



The above will again trigger the default reset event, and only reset the fields not clear. Clearing form is possible, didn't you try this?

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i tried its working....can i implement in my forum..what is "a" in this--- ' onClick="return a=clearFields()" '
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

The default behavior of submit button is to submit the form data, and reset button is to reset the form data so implicitly it calls document.form.reset(). Now to change it's behavior you need to pass a false value to it. So as per the code, clearForm method returns a false value which is assigned to variable a, which is further passed to the reset method.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k...thanks for you help..i had another problem..in my form..i'll post it as another question...can you check it and provide me what to do...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Just for a note, if you wish to clear multiple fields you can have a look on the following code snippet



I didn't exactly understand what exactly you mean by
in my form..i'll post it as another question.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
thanks..i'll try it ....not that what you are understanding...for check boxes im asking...i posted my problem..
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

check box solution is already given in the code, give it a look.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k..i'll try it and let me know the process
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Swastik Dey wrote:The default behavior of submit button is to submit the form data, and reset button is to reset the form data so implicitly it calls document.form.reset(). Now to change it's behavior you need to pass a false value to it. So as per the code, clearForm method returns a false value which is assigned to variable a, which is further passed to the reset method.

But if you're not using the return value from the reset function there's no reason to assign it to a value--just return the results of the function execution. Otherwise it's just unnecessary clutter.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Thanks for the clarification.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

madhuri kunchala wrote:yes..it is related to jsp..so i posted in jsp forum..it contains javascript also..

It is not related to JSP. This question has nothing at all to do with JSP. This is purely an HTML and JavaScript issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
thanks to Swastik Dey ...what he suggested i implemented its working fine...thanks for this forum...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with jsp for reset() method
 
Similar Threads
Question on jQuery ajax functionality & troubleshooting called bean in JSF page
struts-2 (set values to action class)
problem in getting already existing values
spaces while populating using s:iterator
when i retrive data from access it showing empty page in tomcat