Bookmark Topic Watch Topic
  • New Topic

problem in reset() function

 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • 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



clear.js

 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
As far as I know reset does not clear the text fields, rather it populates the text fields with initial values.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Report post to moderator
it will clear all the fields...by using 'reset' command
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Will it? Let's try this



I have a default value as hello in the text field. If I click reset nothing happens. Now lets change the value in the text field say hi, and click reset, now we get the text field displaying hello.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Report post to moderator
the problem is the default value. if default values is not given it'll work. the code is

 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
That is what I was trying to say,
As far as I know reset does not clear the text fields, rather it populates the text fields with initial values.
it will reset the text fields with initial contents. So if your value is blank you get blank or else you get the default value.
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok..i got your point..i had doubt that in my modify page im getting the values from already existing one...so im unable to reset the fields..is there anyother way to do that...i had posted my code in forum...can you once check it...and tell me is there anyother solution
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
//way 1 if your button type is reset

<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>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
Do not cross post.

http://www.coderanch.com/t/504657/HTML-JavaScript/jsp-reset-method

closing this

Eric
 
    Bookmark Topic Watch Topic
  • New Topic