hello. im not sure if this is the right forum because it is about php echo AND js but since it is about echoing i thought this forum will be better. sorry if i asked in the wrong forum.

Anyway, so i want to know if echoing a js script will work? Like for instance as usual we write js in <head> but if it were to be echoed, is that something that is done?

i was thinking of echoing a script for datetimepicker plugin.

i tested this:

echo "<script src='js/jquery 1.8.2.js'></script>";
echo "<script src='js/jquery-ui 1.8.2.min.js'></script>";
echo 
    "<script type='text/javscript'>
        $(document).ready(function(){
            $(\"#button\").live(\"click\", function(){
                alert(\"click\");
            });
        });
    </script>";

nothing happens on click though, so is it not allowed or something?

yes, im using an older version of js when i can just use the latest and .on() but i will upgrade soon.

TIA!

Try not to let this embarrass you too much ok?

You misspelled "javascript"

<script type='text/javscript'> <!-- vowels bro/sis, VOWELS! -->

ah crap. well either way that did not solve it. thanks for pointing that out though. btw should i have posted this in the js forum instead? :s

Well I guess we'll have to determine that after we know what the problem is, however the issue does seem to be JS related.

Is there any other JS on the page that could be broken?

Because here's what I'm testing:

<?php
    echo "<script src='https://code.jquery.com/jquery-1.8.2.min.js'></script>";
    echo "<script src='https://code.jquery.com/ui/1.9.2/jquery-ui.js'></script>";

    echo 
        "<script type='text/javascript'>
            $(document).ready(function(){
                $(\"#button\").live(\"click\", function(){
                    alert(\"click\");
                });
            });
        </script>";
?>

<input type="button" id="button" value="Click Me" />

As you can see, other than changing the path's of jQuery to the hosted one (i even change it back to 1.8.2 to match the version you're using) ... the only other thing I change in your script is the spelling of "javascript" and it works for me.

Everything you're using there should have no version issues either, because even though I would directly use click(), using live() should work because it was not removed until version 1.9

it was actually because of where i placed the echoed script. got confused with these two file im working with. so now i will try with that plugin i mentioned. thanks for your help.

Ahh, glad you got it working! Don't forget to mark the thread solved if you got everything you needed.

Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.