Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with jsp for reset() method

 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im facing problem with reset() function

Which problem ? Can you explain your problem clearly ?
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the "reset" input does not clear text fields. It resets them to their original value.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..it is related to jsp..so i posted in jsp forum..it contains javascript also..
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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]

 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This wont work, because value is applicable to a component like text field, password field etc, not to the form.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried its working....can i implement in my forum..what is "a" in this--- ' onClick="return a=clearFields()" '
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks..i'll try it ....not that what you are understanding...for check boxes im asking...i posted my problem..
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check box solution is already given in the code, give it a look.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k..i'll try it and let me know the process
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanks to Swastik Dey ...what he suggested i implemented its working fine...thanks for this forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic