Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 
    });
});
share|improve this question

1 Answer 1

up vote 5 down vote accepted

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 
    });
}

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

$.getScript('ajax/test.js', function() { updatephp(); });
share|improve this answer
    
Tried this, but something still isn't quite working. I get "Uncaught ReferenceError: updatephp is not defined" –  bpmccain Mar 8 '11 at 15:28
    
Try to put the function in "$(function() { }" block ?! –  Akarun Mar 8 '11 at 15:54
    
Ok, so I just noticed an extra closed bracket (after 07 on line 3). Once I removed that, this worked great. Thanks. –  bpmccain Mar 8 '11 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.