Current location: Hot Scripts Forums » General Web Coding » JavaScript » Clear HTML form


Clear HTML form

Reply
  #1 (permalink)  
Old 02-12-04, 07:46 AM
birdie_nam_nam birdie_nam_nam is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Göteborg, Sweden
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Clear HTML form

Dear experts!

I have a form (<FORM NAME="config"...) on a HTML page, containg a lot of inputs (tempattr5, num_Bi, ...). I clear these by this little script (launched when clicking a button):

function form_clear()
{
document.config.tempattr5.value="";
document.config.num_Bi.value="";
document.config.num_Bf.value="";
document.config.num_Bc.value="";
document.config.num_f1.value="";
document.config.num_f2.value="";
document.config.num_Dk.value="";
document.config.num_Dc1.value="";
document.config.num_Dc2.value="";
document.config.num_alpha.value="";
document.config.num_beta.value="";
document.config.num_d.value="";
document.config.MeanGrindingAllowance.value="";
document.config.PeakGrindingAllowance.value="";
document.config.DesiredSurfaceRoughness.value="";
return true;
}

Since this kind of procedure is wanted on a lot of pages, I wonder if there is any way to clear all inputs of the form "config". You see, there are different elements in evey page, and I would not like to waste my time finding and listing them all. Something like...

for all inputs X in document.config do X.value="";

Anyone that can help me?

Best regards, Sebastian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-12-04, 09:01 AM
snaip's Avatar
snaip snaip is offline
iNET Interactive
 
Join Date: Nov 2003
Posts: 998
Thanks: 2
Thanked 7 Times in 6 Posts
Use the reset button within your <FORM> tags:

Code:
<input type="reset" value="Clear Fields">
The reset button erases all the information in all the fields in the form.
__________________
Regards,
Ahmad Permessur
Team HotScripts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-12-04, 09:05 AM
birdie_nam_nam birdie_nam_nam is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Göteborg, Sweden
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, Snaip, but that's not what I'm after.
The method you propose will reset all fields to their original values, not clear them. For example a tag like
<INPUT TYPE="text" VALUE="1.23">
will be resetted to "1.23". I want them to go blank.

Any more ideas?

/Sebastian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-12-04, 09:21 AM
snaip's Avatar
snaip snaip is offline
iNET Interactive
 
Join Date: Nov 2003
Posts: 998
Thanks: 2
Thanked 7 Times in 6 Posts
How about adding this onSubmit function to your form:

Code:
<FORM name="myForm" onSubmit="document.myForm.content.value=''">
__________________
Regards,
Ahmad Permessur
Team HotScripts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-12-04, 09:41 AM
birdie_nam_nam birdie_nam_nam is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Göteborg, Sweden
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hmmm... Still, Ahmad, I don't think you really understand my needs

Since english is not my native language, I understand that I can be hard to follow from time to time.

Really, I want a button located in the end of the form, acting exactly like the "Reset" button you proposed earlier, but instead of resetting the values in the different inputs of the form, it will clear them.

Sorry for giving you a hard time!

/Sebastian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-13-04, 10:58 AM
snaip's Avatar
snaip snaip is offline
iNET Interactive
 
Join Date: Nov 2003
Posts: 998
Thanks: 2
Thanked 7 Times in 6 Posts
Finally got you, but I fear I don't really have an answer to your prob...
__________________
Regards,
Ahmad Permessur
Team HotScripts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 02-16-04, 01:57 AM
birdie_nam_nam birdie_nam_nam is offline
Newbie Coder
 
Join Date: Feb 2004
Location: Göteborg, Sweden
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
OK, thanks for all your troubles. Got an excellent answer on another place. I might as well share it with you:

for (i=0;i<document.config.elements.length;i++)
{
if (document.config.elements[i].type == "text")
{
document.config.elements[i].value="";
}
}

Here, I am also testing if it is a text box, to avoid clearing for example buttons.

/Sebastian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 04:06 AM
php form to html file arnec PHP 1 01-21-04 11:14 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
how do i re-fill the html form??? gaurav_sting PHP 1 12-21-03 01:13 PM
form to sql to html cadtank New Members & Introductions 3 06-23-03 10:37 PM


All times are GMT -5. The time now is 10:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.