You are viewing limited content. For full access, please sign in.

Question

Question

Clear Table Values

asked on April 16

I have a table that is populated via a lookup from 2 dropdown fields (Term and Week). I want to be able to clear the table back to an empty table before the user can select another Term or Week.

I found a forum that showed how to add a Custom HTML button that reset the whole form. I was hoping I could do something similar but just the selected table?

This is the Custom HTML to reset the whole form - <input type="reset">

 

Untitled.jpg
Untitled.jpg (102.79 KB)
0 0

Answer

SELECTED ANSWER
replied on April 16

Hi Jonathan,

To clear values from a table you can add a button to the form using the following custom HTML:

<button type="button">Clear table</button>

Then, you can add the following JavaScript, which clears the table when the button is clicked. To use this script on your form, replace #q10 with the ID or class of your custom button; replace #q7 with the ID or class of your table.

$(document).ready(function() {
   $('#q10').click(function(){ //wait for button click
      $('#q7 tr').each(function() { //iterate through rows of table
         $(this).find('td').each(function () { //iterate through cells in row
           $(this).find('input, textarea').val(''); //clear cells
         });
       });
    }); 
});

It is worth noting that the script above assumes that your table is made up of single line and multi line fields; if you are using other field types in your table, the script will need to be modified slightly. Additionally, since you mentioned that you don't want the user to be able to make a new dropdown selection until the table is cleared, you may want to add script to make the dropdowns read-only until the button has been clicked.

Hope this helps, and please let me know if you have any further questions!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.