php calling JS
Permalink
Why in the world will this not work?
With a JS function looking to run a simple timer function and document.write it's results to the <div id="timer_1"></div>.
Firebug shows the trouble is in the JS function never getting the call to run. The JS function is inside an addHeaderItems js page that shows loaded in the browser source.
(Either help me or stick and fork in me - I don't think I care anymore.)
EDIT: BTW, it's not bound to a DOM event for a reason. If a condition is met in PHP then it runs into the script which will display the timer_1 results.
I'm loading this variable with html text: $html .= ' ...<td><div id="timer_1"> </div>' //turn the quotes off ?> // get out of php <script type="text/javascript">timequote()</script> // print <script> function call <?PHP // back into php '</td>'; //finish the html line
With a JS function looking to run a simple timer function and document.write it's results to the <div id="timer_1"></div>.
Firebug shows the trouble is in the JS function never getting the call to run. The JS function is inside an addHeaderItems js page that shows loaded in the browser source.
(Either help me or stick and fork in me - I don't think I care anymore.)
EDIT: BTW, it's not bound to a DOM event for a reason. If a condition is met in PHP then it runs into the script which will display the timer_1 results.
Hi Scott,
Thanks for the reply. I had it working, but then lost it. I'm sure your suggestions will work, but I discovered the root of my frustration was that the JS code I temporarily placed inside a default .js addHeaderItem upload (ccm.search.js) locked up and froze - even after commenting them out and reloading - which is weird (to me).
I realize the standard C5 practice and this is a very unique thing I'm shooting for. I thought it best to inject my js into the default file in order to see if the look was what I wanted before making the effort to follow c5 protocol. I had no idea it would freeze/lock the page from working.
I think I've learned that the c5 js scripts are called through bindings to the css in the DOM. Still, I would not have thought the page would lock down - especially considering that it still locks down even after my function is commented out - and I don't see a real problem with my code, so I think it's more a JQuery/CSS binding conflict. (Originally, I had it in it's own object but then simply made the Window it's parent when trying to get things to work.)
It ran long enough for me know that the look created by having the js timing event run when a php condition is met - yes, by refreshing the page, saving to the tables and reloading the page in order to bring other changes to the php view - and not a DOM event (to initiate the js function) is exactly what I want. Now I've got to find a way to make it work cleanly in c5.
I am reading Andrew's "Javascript/JQuery and C5" article:http://www.concrete5.org/documentation/how-tos/javascript-jquery-an... in hopes to getting a clue to the conflict. Any other advice/direction/guidance is appreciated.
Thanks.
Rick
Thanks for the reply. I had it working, but then lost it. I'm sure your suggestions will work, but I discovered the root of my frustration was that the JS code I temporarily placed inside a default .js addHeaderItem upload (ccm.search.js) locked up and froze - even after commenting them out and reloading - which is weird (to me).
I realize the standard C5 practice and this is a very unique thing I'm shooting for. I thought it best to inject my js into the default file in order to see if the look was what I wanted before making the effort to follow c5 protocol. I had no idea it would freeze/lock the page from working.
I think I've learned that the c5 js scripts are called through bindings to the css in the DOM. Still, I would not have thought the page would lock down - especially considering that it still locks down even after my function is commented out - and I don't see a real problem with my code, so I think it's more a JQuery/CSS binding conflict. (Originally, I had it in it's own object but then simply made the Window it's parent when trying to get things to work.)
It ran long enough for me know that the look created by having the js timing event run when a php condition is met - yes, by refreshing the page, saving to the tables and reloading the page in order to bring other changes to the php view - and not a DOM event (to initiate the js function) is exactly what I want. Now I've got to find a way to make it work cleanly in c5.
I am reading Andrew's "Javascript/JQuery and C5" article:http://www.concrete5.org/documentation/how-tos/javascript-jquery-an... in hopes to getting a clue to the conflict. Any other advice/direction/guidance is appreciated.
Thanks.
Rick
timequote();
});
</script>
$(timequote()); or $(timequote()); might also work
usually with jquery you do a css selector an apply an event to it, or define it on document ready or something..this isn't concrete5 specific at all.