Jump to content
  • 0

Clearing Values in A Search Form


SDmesaweb

Question

I have a search form and a results form on the same page.  I reload the values in the search form (by receiving a parameter) so that the user can see what filters are being used to get the current results. 

image.png.2f7316e249e43fe0f3a141b643223dc2.png

This works great except...

When I try and use the reset() form method it will not remove values that were previously submitted.  I have also tried explicitly setting the value in those fields to nothing using something like this:

function clearForm () 
{

   document.getElementsByName('cbParamVirtual7')[0].value="";
   document.getElementById('cbParamVirtual17').value="";
   document.getElementById('cbParamVirtual18').value="";
   document.getElementById('cbParamVirtual19').value="";
  document.getElementById('caspioform').reset();

}

This does clear the checkboxes but will not clear the text fields if they have already been submitted in a query.  I have attached an screenshot of the search filters.

Any suggestions of how to solve this or work around the issue would be greatly appreciated.

Thanks,

Joel

search-filters.JPG

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 1

Try this:

<p><a onclick="clearForm()" style="cursor:pointer;">Clear Form</a></p>

<script>
function clearForm () {
location.reload("[@cbHostPage]?cbResetParam=1");
}
</script>

Please note that when you search again for something, you need to get rid of "cbResetParam=1" in your URL. This is done when you redirect the page from your search form. As long as you do that, you may be fine.

Let us know whether or not it works.

Link to comment
Share on other sites

  • 0

Yes I referenced that article but the setup is a little different:

Button:

<p><a onclick="clearForm()" style="cursor:pointer;">Clear Form</a></p>

Call this function:

function clearForm () 
{

   document.getElementsByName('cbParamVirtual7')[0].value="";
   document.getElementById('cbParamVirtual17').value="";
   document.getElementById('cbParamVirtual18').value="";
   document.getElementById('cbParamVirtual19').value="";
  document.getElementById('caspioform').reset();

}

 

As you can see I have tried several different methods to get the desired result, none of them being completely successful.

Link to comment
Share on other sites

  • 0

No such luck.  It reloads the page but the values in search form persist as well as the filtered data.

Edit: Got this to work.  I took the action out of the on click function and just made it a generic link.

<p><a href="[dataPageURL]&amp;cbResetParam=1">Clear Form</a></p>

Works great!  Thanks for the suggestion.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...