How to reset form fields selectively ?

C

cotton_gear

Hello,

When I clicked on the Reset button I need to reset only few fields
selectively. How do i achieve it using javascrript ?
Actually, when reset is clicked, even hidden fields are reset. I need
to prevent this.

Please suggest, i ma quite tensed as the deadline is close.

Thanks a ton,.
CG
 
R

RobG

cotton_gear said:
Hello,

When I clicked on the Reset button I need to reset only few fields
selectively. How do i achieve it using javascrript ?
Actually, when reset is clicked, even hidden fields are reset. I need
to prevent this.

Please suggest, i ma quite tensed as the deadline is close.

The simple answer is it can't be done - a reset button resets all the
controls in a form to their initial value.

You could create your own button that changes the values of some
controls to something which might be their initial value, but you'll
have to store the control names or references and values somewhere (say
in an object) and manually go to each control and change its value.

Remember that browsers without scripting won't be able to use your
quasi-reset buttons.
 
M

Matt Kruse

RobG said:
You could create your own button that changes the values of some
controls to something which might be their initial value, but you'll
have to store the control names or references and values somewhere
(say in an object) and manually go to each control and change its
value.

You don't actually need to store the initial state, since every form object
already stores its initial state as properties of itself.
Using my functions at http://www.JavascriptToolbox.com/validations/ you can
easily reset a form field by doing:

setInputValue(obj,getInputDefaultValue(obj));

I suppose I could create a resetInput() that does this specific task also.
 
R

RobG

Matt said:
You don't actually need to store the initial state, since every form object
already stores its initial state as properties of itself.

Ah yes, that would be the element's defaultValue property. Hey, it was
late...


[...]
 
T

Thomas 'PointedEars' Lahn

Jasen said:
don't use a reset button, use a regular button and have the onclick run
javascript which accesses the apropriate form fields and resets them.

And be sure to generate that button through "javascript".


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top