Solved

reset form fields to nothing

Posted on 2007-03-26
4
193 Views
Last Modified: 2010-04-16
hi everyone,
using the form reset button it only resets to the values that the page loads with..

Is it possible to clear all values within the form, even though its prepopulated with session data.

i.e. set all text fields to '' and set all radios to empty?  
thanks
0
Comment
Question by:jimbona27
4 Comments
 
LVL 10

Accepted Solution

by:
Jaax earned 50 total points
ID: 18792385
There is no predefined function supplied by javascript to clear all the values.
You have to do it explicitly; something like this inside the script:
for(i=0;i<document.forms[0].elements.length; i++){
  ele = document.forms[0].elements[i];
  if(ele.type == "text" || (ele.type == "textarea" ){
     ele.value == "";
 }else if(ele.type == "radio") {
     if(ele.length){
         for(j=0; j<ele.length;j++){
             ele[j].checked = false;
         }
     }else{
       ele.checked = false;
     }
     //Continue checking for all the other element types like check box, hidden etc
 }
 

}
0
 

Author Comment

by:jimbona27
ID: 18816066
just checking it out, got a few problems with the code so just debugging it. let you know.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Capture logon name 13 70
Angular - example works but my data is different 13 26
simple javascript form validation 2 17
How to convert from xls to xlsx using java 7 35
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now