469,955 Members | 2,606 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

How to determine '+ variable +' in var url string?

Hello,

I am trying to determine what the appropriate variable is to place between plus (+) tags in in a javascript var url string. For instance I have the following code:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.    function refreshData() {
  3.    var url = "/pulldata.php?p=" + tags + "&s=" + statistic + "";
  4.  
  5. // rest of js
  6. </script>
  7.  
Essentially, what is the definition of + tags + and + statistic + and how do you determine what variables they are supposed to be?
Oct 19 '10 #1
2 1610
Dormilich
8,652 Expert Mod 8TB
tags and statistic seem to be 2 global variables.
Oct 19 '10 #2
How would I define the global variable for $statistic_id from this bit of code:

Expand|Select|Wrap|Line Numbers
  1. <div id="playerstats">
  2. <table width="265px" border="0" >
  3. <? $i = 0; foreach ($combine as $statistic_id => $stat_values): ?>
  4. <tr>
  5. <td style="vertical-align:middle; font-size : 11px;">
  6.   <input type="checkbox"  id="checkbox_<?= $statistic_id; ?>" <?= $i==0 ? 'checked="checked"' : null; ?> />
  7.   <label for="checkbox_<?= $statistic_id; ?>"><?= getStatisticFromId ( $statistic_id ); ?></label>
  8. </td>
  9. </tr>
  10. <? $i++; endforeach; ?>
  11. </table>
  12. <script>
  13. </div>
  14.  
$statistic_id is a variable number that is associated with the checkbox. When someone clicks a new checkbox they are effectively selecting a new $statistic_id. I need to define $statistic_id as a global variable so that I can incorporate it into my AJAX. Please see this code below:

Expand|Select|Wrap|Line Numbers
  1.  function refreshData() {
  2.    var pid = <?= $_GET['p']; ?>;
  3.    var statistic_id = ???;
  4.    var url = "/pulldata.php?p=" + pid + "&s=" + statistic_id + "";
  5.    $.getJSON( url,
  6.    function(data){
  7.      for ( pid in data ) {
  8.        for ( statistic_id in data[ pid ] ) {
  9.          console.log( data[ pid ][ statistic_id ] );
  10.          drawLineOnGraph( data[ pid ][ statistic_id ] );
  11.       }
  12.     }
  13.    } );
  14.   }
  15.  
If you know of a way to make $statistic_id a global variable that I can incorporate into my AJAX that would be helpful. Thanks.
Oct 19 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by MCollins | last post: by
6 posts views Thread by lisa.lin | last post: by
2 posts views Thread by charliefortune | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.