0

I have this form:

<form onsubmit="serverconnect('Div1', 'query.php'); return   
false;" 
Minimum Discount: <br />
<input type="radio" value="20%" name="discount" /> 20% <br />
<input type="radio" value="15%" name="discount" /> 15% <br />
<input type="radio" value="10%" name="discount" /> 10% <br />
<input type="radio" value="5%" name="discount" /> 5% <br />
<input type="submit" value="Refine Search" />
</form>

On submit, the form calls the following ajax script

<script language="javascript" type="text/javascript">


var xmlhttp = false;


if (window.XMLHttpRequest)
{
    xmlhttp = new XMLHttpRequest(); 
}
else if (window.ActiveXObject)
{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}


function serverconnect(divID, datalocation)
{
var1=$clickvalue;
if(xmlhttp)
{
    var obj = document.getElementById(divID);
    xmlhttp.open("GET", datalocation);

    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 &&
        xmlhttp.status == 200)
        {
        obj.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null); 
}

}
</script>

I need to get the form data through to my query.php page (which is what the ajax is outputtng) to modify its output, without using the jquery library.

So is there a way to pass the form data through the ajax function to the page that the function calls?

1 Answer 1

4

Yes you can pass form data using ajax. As you are using GET method only you have to embed your data with the page like this

<input type="radio" value="20%" name="discount" id="discount" /> 20% <br />


var obj = document.getElementById(divID);
var disc = document.getElementById("discount");
xmlhttp.open("GET", datalocation + "?disc="+disc);

and in query.php use $_GET['disc'] for getting get data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.