Jump to content

Javascript Help Needed


Recommended Posts

When I had my onboarding with Caspio helped with some Java Script to replace a blank space with " OR " so we could search on a field using "Contains" versus "Equals". We are now trying to duplicate this code in a new data page and it is not working. The data page where it does work is "Search Bar" on field "Virtual4" and the code is in the header and the footer. The results are then passed to another data page. 

I now want to create a data page where the search is contained in the page and the results are not passed. 


The functionality we need is to cut & paste style #'s into the search box and upon clicking submit the script runs and replaces the space with " OR " and the "contains" search runs. Here is an example use case

  1. Cut and paste "CM7661 CM7662 CM7854"
  2. Click Submit
  3. Script runs and replaces the spaces with " OR " and the query looks like "CM7661 OR CM7662 OR CM7854"
  4. The results for the 3 style numbers are returned
     
The code we have in the header is:

<div id="search">

The code we have in the footer is:

<script>
document.getElementById('search').onsubmit= function (){

var txt = document.getElementById('cbParamSeason_Table_Style').value;

document.getElementById('cbParamSeason_Table_Style').value = txt.replace(/\s+/g, " OR ");
}
</script>


Why is this not working?

Thanks,

Jeff

Link to comment
Share on other sites

  • 2 weeks later...

Hi Jeff,

 

I can share with you a solution which I have been using for a similar case.

You will need to create to Datapages.

1. Submission form - this Datapage will consist of Virtual fields;

2. Report Form - this Datapage will be filtered based on received from Submission form; 

Here some settings for each Datapage:

  1. Submission form 
    • Virtual field should pass parameter on exit;
    • Footer of Datapage should have following JS:
    • <script>
      
      function Replace(){
      
      var a = document.getElementById("cbParamVirtual1").value;
      
      document.getElementById("cbParamVirtual1").value=a.replace(/\s+/g, '||cb||');
      
      }
      
      document.getElementById("caspioform").onsubmit=Replace;
      
      </script>

      Destination after record submit option should be set to "Go to Datapage".  You should specify Report page in Datapage name section;

  2.  Report Form
    • Search form should be enabled;
    • Form element Listbox should be selected for the filtering field;
    • Comparison type "Equal" should be selected;
    • In the Advanced tab of filtering field, you should configure:
      • Allow multi-select - checked; Match any (OR) radio button selected;
      • Receive value or parameter  - checked; Value: "External Parameter" - please specify the name of parameter from Submission form;
    • Use auto-submit JS in the Footer of Search Form;

 

Note: You should use "space" to separate searchable values;

Hope this helps.

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
Reply to this topic...

×   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...