Tagged: javascript
-
AuthorPosts
-
July 16, 2016 at 5:34 pm #661667
I am so frustrated with this. I see lots of topics, and every answer seems different. I am using an enfold child Theme.
All I want to do is add about 10 Javascript functions that I can execute from a single page or from any page. I’d also like to attach an onchange event to several input fields that execute these Javascript routines. Essentially, I just want to attach an onchange event to a text input or other field, in order to update another field and keep them in sync
I think I’m supposed to us the child theme’s functions.php file, but see so many different examples in the forums that I don’t know what is the correct way to do it. Since this is such a common request, is there not a piece of documentation that explains how to do it properly instead of trying to extract the right answer from all the specific questions?
- This topic was modified 8 years, 4 months ago by rogersparks.
July 17, 2016 at 4:59 pm #661787Hey Roger,
I’m not sure exactly what it is you want to implement, could you try to explain a bit further exactly that you want to achieve please? If you’re only looking to add javascript on one page I would try using the Code Block element in the builder to see if that works out for you.
Thanks,
RikardJuly 18, 2016 at 5:29 pm #662147Hi Rikard,
Thank you for your response.
We desperately need an input type=”range” slider to use on our website, and since there seems to be no good plugin that has this input object that allows us to attach events to the slider, we decided to write our own. The steps we used:
1. We styled a generic slider in the Quick CSS for Enfold;
2, We use the Code Block element to add the slider to every page we need, including supporting objects;
3. We wrote a common set of Javascript to respond to events on the slider and supporting objects that is now accessible from any page the slider is placed on. We did not want to have to put all this code on every page.To do this, we put the Javascript in the functions.php file of the Enfold Child theme. We added it as follows, after scouring the support posts to look for an example. Since this seems such a common need, it would have been great to have it in the documentation somewhere.:
—————————————————————-
function add_custom_script(){
?>
<script>
// all custom code went here
</script>
<?php
}
add_action(‘wp_footer’, ‘add_custom_script’);—————————————-
So, my question’s are:
1. Is this the right way to do this, or is there a better way?
2. Does this put the code in only if we show a footer on the page, and should we put it somewhere else, and where, and how?It would have obviously been better for us if we had an input type = range object available in Enfold, to which we could assign an ID and thus attach events.
Thanks for your help.
Roger
July 19, 2016 at 12:39 pm #662438 -
AuthorPosts
- You must be logged in to reply to this topic.