Getting multiple vars from php to javascript -


i need move 2 variables database javascript, things tried far didn't work out.

i've tried ajax far know can't send them separately necessary.
putting variable in url isn't option either since requires refreshing page. because vars used make changes in css , script needs run multiple times each run undo changes.
i've tried use <?php $var ?> within java script. though works vars outside of function, not work var within function.

script i'm using @ moment test script, suggestions welcome.

<?php if(isset($_post["colourcheck"])){     $colour = "red";     $number = 1;     echo $colour, $number;     exit(); } ?> <!doctype html> <html> <head>     <title></title>     <script src="../scripts/main.js"></script>     <script>         function checkcolour() {             var ajax = ajaxobj("post", "test2.php");             ajax.onreadystatechange = function () {                 if (ajaxreturn(ajax) == true) {                     var colour = ajax.responsetext;                     _("unamestatus").innerhtml = colour;                 }             }             ajax.send("colourcheck=");         }     </script> </head> <body>     <div class="colour 1" onclick="checkcolour()">1</div>     <div class="colour 2" onclick="checkcolour()">2</div>     <div class="colour 3" onclick="checkcolour()">3</div>     <span id="unamestatus"></span> </body> </html> 

if want use server values in javascript use data-attributes in tags. ex:

<input id="my_input" name="color" data-identifier='<?=$server_value?>' /> 

now in js can anywhere like: // jquery $(function() { alert($('#my_input').data('identifier')); })

//plain js document.getelementbyid('my_input').dataset.identifier;  

hope you.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -