Jump to content

Javascript Duplicate Criteria1 to Criteria2


Recommended Posts

I have a search criteria that needs the same data in both criteria fields in order to function properly, but I want to hide the second field and have it automatically enter whatever number the user inputs into Criteria1.

I've tried a few older Javascript codes that I found on this forum but none of them have worked. 

Any assistance would be amazing!

Link to comment
Share on other sites

Hello @Klib7,

Do you need to apply this to 2 separate search fields or 1 search field with Criteria?

JE39x4X.png

It is important to reference the fields. 

For case 1 you can add this code in the Footer section of the Search page:
 

<script>
if (document.DataPageReadyHandler == undefined) {
    const DataPageReadyHandler = (e) => {
     if (e.detail.appKey != '[@cbAppKey]') { return }
      
        const fieldOne = document.querySelector('#Value1_1');
        const fieldTwo = document.querySelector('#Value2_1');
        fieldOne.addEventListener('change', function(){
            fieldTwo.value = event.target.value;
        })
    }
    
    document.addEventListener('DataPageReady', DataPageReadyHandler)
    document.DataPageReadyHandler = 'Enabled'
    }
</script>

For case 2:
 

<script>
if (document.DataPageReadyHandler == undefined) {
    const DataPageReadyHandler = (e) => {
     if (e.detail.appKey != '[@cbAppKey]') { return }
     
        const criterionOne = document.querySelector('#Value1_1');
        const criterionTwo = document.querySelector('#Value1_2');
        criterionOne.addEventListener('change', function(){
            criterionTwo.value = event.target.value;
        })
    }
    
    document.addEventListener('DataPageReady', DataPageReadyHandler)
    document.DataPageReadyHandler = 'Enabled'
    }
</script>

If the code doesn`t work, please provide a screenshot of the Search page as on the screenshots examples that I added in this post above. 

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