Jump to content

Cannot reset this form. Weird!


kristo5747

Recommended Posts

Greetings!

 

I created this form that works like a charm (thanks to the help I got here...), captures data in my db and sends email.

 

Suppose user Joe hits the RESET button before he clicks SUBMIT, all fields are reset. If Joe hits the RESET button AFTER he clicked SUBMIT (e.g. to make a new submission)...nothing gets reset.

 

Here's my code...

 

...  <form enctype="multipart/form-data" method="post" name="webform" onsubmit="return validate(this)" action="<?php echo $_SERVER['PHP_SELF'];?>">
   <h2>Title of request:</h2>
   <input type="text" tabindex="0" name="request_title" maxlength="255" size="62"
     value='<?php echo $_POST['request_title'];?>'
     ><br><br>
   <h2>Please describe your request in detail:</h2><br>
   <textarea tabindex="1" name="request_description" cols="87" rows="10" ><?php echo $_POST['request_description'];?></textarea>
   <table border="0" cellspacing="3" cellpadding="3">
    <tbody>
     <tr>
      <td><fieldset id="output"><legend>Output Options: </legend>
        <input type="checkbox" tabindex="2" id="chb0" name="check_output[]" value="CSV" <?php if(isset($_POST['check_output']) && in_array('CSV', $_POST['check_output'])) echo ' CHECKED ';?>>CSV<br>
        <input type="checkbox" tabindex="3" id="chb1" name="check_output[]" value="Excel" <?php if(isset($_POST['check_output']) && in_array('Excel', $_POST['check_output'])) echo ' CHECKED ';?>>Excel<br>
        <input type="checkbox" tabindex="4" id="chb2" name="check_output[]" value="Email" <?php if(isset($_POST['check_output']) && in_array('Email', $_POST['check_output'])) echo ' CHECKED ';?>>Email<br>
        <input type="checkbox" tabindex="5" id="chb3" name="check_output[]" value="HTML" <?php if(isset($_POST['check_output']) && in_array('HTML', $_POST['check_output'])) echo ' CHECKED ';?>>HTML<br>
        <input type="checkbox" tabindex="6" id="chb4" name="check_output[]" value="None" <?php if(isset($_POST['check_output']) && in_array('None', $_POST['check_output'])) echo ' CHECKED ';?>>None<br>
        <input type="checkbox" tabindex="7" id="chb5" name="check_output[]" value="PDF" <?php if(isset($_POST['check_output']) && in_array('PDF', $_POST['check_output'])) echo ' CHECKED ';?>>PDF<br>
       </fieldset></td>
      <td><fieldset> <legend>Frequency: </legend>
        <input type="radio" id="rad0" tabindex="8" name="Frequency" value="One Time" <?php echo ($_POST['Frequency']=="One Time")?"CHECKED":""; ?>>One Time<br>
        <input type="radio" id="rad1" tabindex="9" name="Frequency" value="Daily" <?php echo ($_POST['Frequency']=="Daily")?"CHECKED":""; ?>>Daily<br>
        <input type="radio" id="rad2" tabindex="10" name="Frequency" value="Weekly" <?php echo ($_POST['Frequency']=="Weekly")?"CHECKED":""; ?>>Weekly<br>
        <input type="radio" id="rad3" tabindex="11" name="Frequency" value="Monthly" <?php echo ($_POST['Frequency']=="Monthly")?"CHECKED":""; ?>>Monthly<br>
        <input type="radio" id="rad4" tabindex="12" name="Frequency" value="Ongoing" <?php echo ($_POST['Frequency']=="Ongoing")?"CHECKED":""; ?>>Ongoing<br>
       </fieldset></td>
      <td><fieldset> <legend>Request Type: </legend>
        <table border="0" cellspacing="3" cellpadding="3">
         <tbody>
          <tr>
           <td><fieldset id="myfieldset"> <legend>Data: </legend>
             <input type="radio" id="req0" tabindex="13" name="request_type" value="Add Data" <?php echo ($_POST['request_type']=="Add Data")?"CHECKED":""; ?>>Add<br>
             <input type="radio" id="req1" tabindex="14" name="request_type" value="Extract Data" <?php echo ($_POST['request_type']=="Extract Data")?"CHECKED":""; ?>>Extract<br>
             <input type="radio" id="req2" tabindex="15" name="request_type" value="Update Data" <?php echo ($_POST['request_type']=="Update Data")?"CHECKED":""; ?>>Update<br>
             <input type="radio" id="req3" tabindex="16" name="request_type" value="Validate Data" <?php echo ($_POST['request_type']=="Validate Data")?"CHECKED":""; ?>>Validate<br>
            </fieldset></td>
           <td><fieldset id="myfieldset"> <legend>Report: </legend>
             <input type="radio" id="req4" tabindex="17" name="request_type" value="New Report" <?php echo ($_POST['request_type']=="New Report")?"CHECKED":""; ?>>New<br>
             <input type="radio" id="req5" tabindex="18" name="request_type" value="Modify Report" <?php echo ($_POST['request_type']=="Modify Report")?"CHECKED":""; ?>>Modify<br>
            </fieldset></td>
           <td><fieldset id="myfieldset"> <legend>Table: </legend>
             <input type="radio" id="req6" tabindex="19" name="request_type" value="New Table" <?php echo ($_POST['request_type']=="New Table")?"CHECKED":""; ?>>New<br>
             <input type="radio" id="req7" tabindex="20" name="request_type" value="Modify Table" <?php echo ($_POST['request_type']=="Modify Table")?"CHECKED":""; ?>>Modify<br>
            </fieldset></td>
          </tr>
         </tbody>
        </table>
       </fieldset></td></tr>
    </tbody>
   </table>
   <br>
   <input type="hidden" value="Created" name="status">
   <input type="submit" id="sd" tabindex="24" value="submit" name="submit">
   <input type="reset" onclick="resetform();" id="rs" tabindex="25" name="reset" value="reset">
  </form>...

 

I created a small javascript that I called the head() section of my page.

 

function resetform(form) {
// resets title
document.forms[0].request_title.value = "";
...
}

 

Nothing happens! What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/198178-cannot-reset-this-form-weird/
Share on other sites

Is there a javascript error? Is that form the first form that appears on the page? Try using the form name instead of the index:

 

document.webform.request_title.value = "";

 

There was no error. Nothing happened. Anyway I figured it out:  I edited my code from

 

<input type="reset" onclick="resetform();" id="rs" tabindex="25" name="reset" value="reset">

 

to

 

<input type="BUTTON" onclick="resetform();" id="rs" tabindex="25" name="reset" value="reset">

 

Of course, it worked. Changing the input type was all I needed to do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.