Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

How do I clear textboxes with javascript when the user refreshes the page?

Hi:
I need to clear a bunch of textboxes when the user clicks the refresh button. Right now, the values that the user enters into the textboxes stay there for some reason when the page is refreshed.

I need this to work in Firefox and IE and I also need it to work when the user clicks a reload button that I am creating on the page.

Please help.

Thanks.
0
bolenka
Asked:
bolenka
  • 4
  • 4
  • 2
  • +2
4 Solutions
 
DooDahCommented:

Can you send a URL ?   Example ?
0
 
DooDahCommented:

>> when the user clicks a reload button that I am creating on the page.


<form name="data_entry" action="#">

Company Name: <input type="text" size="35" name="company_name">

Select Business Type: <input type="radio" name="business_category" value="1"> Manufacturer
<input type="radio" name="business_category" value="2"> Whole Sale Supplier
<input type="radio" name="business_category" value="3"> Retailer
<input type="radio" name="business_category" value="4"> Service Provider

Email Address: <input type="text" size="30" name="email">

Keep Information Private: <input type="checkbox" name="privacy">

<input type="button" name="Reload_form" value="Reload Form" onclick="this.form.reset();">
<input type="button" name="Submit_form" value="Submit Form" onclick="this.form.submit();">

</form>

0
 
bolenkaAuthor Commented:
what if the form fields are dynamic? also, I am talking about somekind of window onload function. Does anyone know how to do this?

I am more concerned with clearing them on page refresh than I am about on submitting. Thanks.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
leakim971PluritechnicianCommented:
0
 
DooDahCommented:

>> Does anyone know how to do this?
YES

 <body onload="document.form_name.reset();">
0
 
InsoftserviceCommented:
hi,

<body onload='Reset()'>


  function Reset()
{
document.formname.reset();
return false;
 }


save the below code as .html and check it out
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
  function Reset()
{
document.xyz.reset();
return false; }

</script>
<body onload='Reset()'>
<form name="xyz" id="xyz" method="post">
<table>
            <tr>
                  <td>
      <input type='text' value="" id='id1' > 
                  </td>
                  <td>
      <input type='text' value="" id='id2' > 
                  </td>
                  <td>
      <input type='text' value="" id='id3' > 
                  </td>
                  <td>
                             <input type='text' value="" id='id4' > 

                  </td>
            </tr>
      </table>




</form>
</body>
</html>



0
 
bolenkaAuthor Commented:
Ok, I'll take a look. Thanks
0
 
DooDahCommented:



>>  @bolenka:   what if the form fields are dynamic?
If your FORM has "Dynamic Data" or "Default" values then "Resetting the Form" or "Reloading the Page" will ONLY give you those "Dynamic Data" or "Default" values back.   What you need to do is CLEAR the "Dynamic Data" or "Default" values

To clear a FORM's TEXTBOXES of "Dynamic Data" or "Default" values eithe ONLOAD or with a BUTTON

ONLOAD METHOD
================
<body onload='Clear_TextBoxes()'>

BUTTON METHOD
===============
<input type="button" name="Reload_form" value="Reload Form" onclick="Clear_TextBoxes();">

function Clear_TextBoxest()
{
document.form_name.textbx_name1.value="";  //  Erase "Dynamic Data" or "Default" value
document.form_name.textbx_name2.value="";  //  Erase "Dynamic Data" or "Default" value
document.form_name.textbx_name3.value="";  //  Erase "Dynamic Data" or "Default" value
return false;
 }

0
 
bolenkaAuthor Commented:
you all helped thanks.
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0
 
bolenkaAuthor Commented:
sure...just posted another one...so check that out too:)
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now