0

I need to dynamically generate and execute some javascript on change of a select box. Right now, I am using a remote php file to generate that javascript (using mysql queries).

I don't know how then to run that javascript in my main page again. I've been playing around with .getscript, but I have no idea if I am heading in the right direction. I'm very new to all of this.

Right now, I am simply using:

$.getScript(url.php);

to call my php file.

My php file produces something like:

$(function() {
    $( "#dateStartMainChartSelect" ).datepicker({ 
        minDate: new Date(2011,03,07)),
        maxDate: +0 
    });
});

1 Answer 1

5

Try to change your PHP to generate a function instead of a "DomReady" script, like this:

function updatephp() {
    $("#dateStartMainChartSelect").datepicker({ 
        minDate: new Date(2011,03,07),
        maxDate: +0 
    });
}

After that you can use the callback function of getScript to start your new function:

$.getScript('ajax/test.js', function() { updatephp(); });
Sign up to request clarification or add additional context in comments.

3 Comments

Tried this, but something still isn't quite working. I get "Uncaught ReferenceError: updatephp is not defined"
Try to put the function in "$(function() { }" block ?!
Ok, so I just noticed an extra closed bracket (after 07 on line 3). Once I removed that, this worked great. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.