How to handle drop down box change event without refreshing page?

Questions by alpeshbsk

Showing Answers 1 - 27 of 27 Answers

Gokul

  • Feb 9th, 2007
 

In < select > use the onChange attribute and call the javascript function function what ever you need to change in the rest of the form.

  Was this answer useful?  Yes

alpeshbsk

  • Feb 9th, 2007
 

i thing this is not the solution because it refreshing a page.

  Was this answer useful?  Yes

adha.manojsingh

  • Feb 13th, 2007
 

Hi We can change the contain of a drop down using AJAX without refresh the page. we can call a AJAX function on the onchange event of drop down.

Piyush Patel

  • Mar 10th, 2007
 

Hi..

All logic should be made in the page when page is first loaded, and when u change drop down box than call javascript function to do anything.

For eg:

If there are two drop down box, and if u want to fill second drop down box as first drop down's change event. than u should make array for that when page is load. and after first's drop down box' change event u have to fill second drop down box's contents with the help of javascript, In this case your page will not refresh.

  Was this answer useful?  Yes

By Adding AJAX and by calling it onchange event of Selection Box


function AjaxFunction(cat_id)
{
var httpxml;
try
  {
  // Firefox, Opera 8.0+, Safari
  httpxml=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
    try
         {
        httpxml=new ActiveXObject("Msxml2.XMLHTTP");
        }
     catch (e)
        {
       try
        {
        httpxml=new ActiveXObject("Microsoft.XMLHTTP");
        }
       catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
  }
function stateck()
    {
    if(httpxml.readyState==4)
      {

var myarray=eval(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);
}


for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcat.options.add(optn);

}
      }
    }
 var url="dd.php";
url=url+"?cat_id="+cat_id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
  }
</script>

  Was this answer useful?  Yes

Heinz Stapff

  • Nov 19th, 2011
 

Try
divId.innerHTML=XMLhttp.responseText
if you want the whole form the whole form has to be posted and urlencoded etc. Just echo back the parts you acctually want with the values you want?

  Was this answer useful?  Yes

Malik Adeel

  • Nov 20th, 2011
 

You don't need AJAX to perform this action, it can be done without using AJAX by onChange() function.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions