Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to RESET only one field in a form???

Status
Not open for further replies.

present2002

Programmer
Jul 5, 2002
9
US
How can you reset one field in a multi-field
form without reseting the remaining fields
 
try this
<html>
<head>
<script>
function resettxt() {
form1.textbox.value = &quot;&quot;;
}
</script>
</head>
<body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;textbox&quot;>
<input type=&quot;button&quot; value=&quot;reset text box&quot; onClick=&quot;resettxt()&quot;>
</form>
</BODY>
</HTML> You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
I have already this method.

The above code reassigns a blank value to that field, it does not reset the value of that field. There is a difference.

I am executing an Onclick event, when SAVEbutton is pressed!

But Still, Thanks for your info :)
 
that clears the text box, not reset it.

to do that, you should do 2 things:

in the onLoad

onLoad=&quot;var defaulttext=document.form.textfield.value&quot;

and in the button put a onclick like this:

onClick=&quot;document.form.textfield.value=defaulttext&quot;

Hope this helps.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
crude but effective
<html>
<head>
<script>
function resettxt(re) {
form1.reset(re);
}
</script>
</head>
<body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;textbox&quot;>
<input type=&quot;button&quot; value=&quot;reset text box&quot; onClick=&quot;resettxt(form1.textbox.value)&quot;>
</form>
</BODY>
</HTML> You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
The reset function accept params? I read in the O'Reilly JS reference in dreamweaver (where i seek info about JS), that the function returns nothing and accept none paramters.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
your right Anikin, when I added more fields it reset all. Had never needed to try this and thought why not present2002 I cant' think of a reason the first psot would not be good for this task. can you explain You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Anikin!

Your cool idea worked perfectedly, Thanks!

Also, onpnt, your code is also correct and makes sense, its only that in my current situation, Anikin's code is doing the job.
 
onpnt,

sounds like present2002 wants to reset the field back to its original text, not just reset it to blank.

=========================================================
if (!succeed) try();
-jeff
 
ya, I got that after the last few posts. I thought that detail might have been good to add to the original question but o'well You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
When loading the page you could copy the whole form into an array, then selectively reset the fields you wish
Code:
var clone = new Array();
function cloneForm(){
  for(var i=0;i<document.formName.elements.length;i++){
    clone[document.formName.elements[i].name]=document.formName.elements[i].value}
}
function resetField(field){
  document.formName[field].value=clone[field];
}
window.onload=cloneForm;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top