Have javascript right, but need to pass variable with ajax, GIVING REP!

Discussion in 'jQuery' started by MarcL, Feb 12, 2011.

  1. #1
    Have javascript right, but need to pass variable with ajax, WILL GIVE REP!

    function showBox() {
    var selectBox = document.getElementById("store").value;
    	if (selectBox == 'N') {
    	document.getElementById("penyard").style.display="none";
    	}else{
    	document.getElementById("penyard").style.display="block";
    		}
    }
    Code (markup):
    so how do I pull the value of selectBox to php without refreshing the page.
    penyard needs the value of selectBox to know what to display.
     
    MarcL, Feb 12, 2011 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    
    data = 'store='+selectBox;
    $.post("page.php",data,function(response, status, xhr)
    {
        if (status == "error")
        {
            alert("Error:"+ xhr.status + " " + xhr.statusText);
        } else {
            Alert("sucess");
        }
    });
    
    Code (markup):
    On page.php, you will get the value $_POST['store'];
     
    ThePHPMaster, Feb 13, 2011 IP