Solved

reset form fields to nothing

Posted on 2007-03-26
4
177 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

18 Experts available now in Live!

Get 1:1 Help Now