Trigger code to run on page when an event of site occurs

I want to have a function written on my sites PAGE execute when a change event on a field in the header occur which runs code on the SITE is execute.

Hi Cliff,

I reread the title, and I think I understand now. you can simply copy the trigger from the site side code and add it to the page. Should work fine and trigger only on that page if that’s what you’re hoping to achieve.

If you want to trigger something on several pages, just keep copy and pasting the trigger and change the code inside.

Hope that helps!

Anney

irs not a question if copying the code. What I want to happen is that when a select is made in a combo box on the header a change event takes place that runs code in the SITE page as it is a header.

when this event happens I pass the value to the PAGE using the session Setitem and getitems and I want to run a function that queries a collection immediatey

so my question is how to trigger this function automatically?

I see. By combo box do you mean a user input box?

Yes that’s correct

A combo box is a dropdown list from which one value can be selected

What I would recommend to do is this. Create an onChange handler for the dropdown. Then drag this handler onto your PAGE code from your SITE code (it should automatically go there first)

This will allow the code to run on a specific page and will negate the need to transfer information from SITE to PAGE. The result should look something like this:

export function yourDropdown_change(event) {
 // Add your code for this event here: 
 let input = $w('#dropdown').value
 
 wixData.query("yourDataset")
 .eq("field", input)
 .find()
 .then( (results) => {
     //the rest of your code here...
 })
}

You can then copy and transfer this to any pages you might need. By taking the handler from SITE and pasting it on PAGE it will trigger and run without needing to transfer any variables from SITE to PAGE.

Hope that helps!

Thanks Anney, thats working fine now. Great!