Link to home
Start Free TrialLog in
Avatar of Easyrider43
Easyrider43Flag for United States of America

asked on

javascript not passing variable

For some reason when I pass the "color" variable php cant pick it up- it just comes up blank. can someone please look at my code and see if im doing something wrong.. thanks guys

if ($id == 'theme')
      {
      echo '<form>';
      echo '<div class="color_option"><input type="radio" name="color" value="#DD597D" onClick="color_changer(this.value,\'center_info\',\'4001\');"/>Red';
      echo '<div class="color_option"><input type="radio" name="color" value="#0000FF" onClick="color_changer(this.value,\'center_info\',\'4001\');"/>Blue';
      echo '<div class="color_option"><input type="radio" name="color" value="#00FF00" onClick="color_changer(this.value,\'center_info\',\'4001\');"/>Lime';
      echo '</form>';
      }

function color_changer(color, divname, userid)
{
document.getElementById(divname).style.background=color;
connect_ajax()
xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("right_side").innerHTML=xmlhttp.responseText;
            /*theme(userid);*/
            return;
            }
      }
xmlhttp.open("GET","../functions/account_settings.php?id=changetheme&do="+userid+"&co="+color,true);
xmlhttp.send();
}



if ($id == 'changetheme')
      {
      
      $theme = $_GET['co'];
      include ('../config/config.php');
      mysql_pconnect ($host, $user, $pass) or die ('Unable To Connect to Database!');
      mysql_select_db('providers') or die ('Unable To Select Database');
      $qry = "UPDATE contractors SET theme ='$theme' WHERE id = '$userid' LIMIT 1";
      echo $qry;
      echo $theme;      
      //$result = mysql_query($qry) or die ('Error in query: $qry. ' . mysql_error());
      mysql_free_result($result);
      }
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

xmlhttp.open("GET","../functions/account_settings.php?id=changetheme&do="+userid+"&color="+color,true);
xmlhttp.send();
ignore my first post;are you getting value here?

function color_changer(color, divname, userid)
{
alert(color)
document.getElementById(divname).style.background=color;
Avatar of Easyrider43

ASKER

yup it alerts me the color but for some reason in the xmlhttp.open string its not reading that "color" variable
I get the userid passed but not the color, am i missing some quote or something????
quotes are correct.
xmlhttp.open("GET","../functions/account_settings.php?id=changetheme&do="+userid+"&co="+color);
they why does it come up as null?
Avatar of Dave Baldwin
In the PHP, are you doing $id = $_GET['id']; first?  If not, then $id is null or non-existent.
Yea its declared first, yet it show's up empty on the $qry script
ASKER CERTIFIED SOLUTION
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that was it, apparently you cant pass a "#" inside a link. Thanks for pointing that out
Glad it worked
Meeran03