Essentially I am trying to call a dynamically created function (whose name could change depending on the $.get call)
I have a PHP file which generates a JavaScript function like so:
widget.php
<?PHP $widgetID=$_GET["w"]; ?>
<script type="text/javascript">
$(document).ready(function() {
function <?PHP echo $widgetID; ?>Hide(){
$("#<?PHP echo $widgetID; ?>Object").attr("display", "none");
}
</script>
The main page contains code that loads this into a <div> tag using $.get()
<div id="widget"></div>
<script>
$( document ).ready(function() {
$.get( "widget.php?w=widget", function( data ) {
$( "widget" ).html( data );
});
});
</script>
What I am trying to do is later call the function that is loaded via the AJAX call (in this case widgetHide()).
Example:
$(document).ready(function() {
$('input:file').change(
widgetHide();
}
});
The function, however, cannot be called. I have tried to call the function in a number of ways (on ajaxComplete, etc), none of which have worked. No matter what I have tried the function that is created widgetHide() cannot be called.
I have seen some similar questions to this, however, none that have function names that may be able to change depending on the variable passed to the call. Although I think the fact that the function name could change is essentially irrelevant to what I am trying to do.
Is there a function to check if the function exists? Is the function out of scope?