hi,
I need suggestion for this.After a particular option selection in my page,how to replace the rest of the contents of the same page with its response,and too making the select action invisible... can i do it using ajax wit html...
for example,i have a select option,where for each option is attached a new set of objects,i want them to be loaded on the same page at run time,without page refresh... plz help me..

Regards,
Suchitra

Yes you can do this with AJAX and Javascript. All you would do is include an event with the HTML.

Here is a quick example.

HTML

<select name="form_option" id="form_option" onchange="check('form_value');">
<div id="thischanges">
</div>

Javascript funtion

<script language="javascript" type="text/javascript">
function getHTTPObject(){
      if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
      else if (window.XMLHttpRequest) return new XMLHttpRequest();
      else {
      alert("Your browser does not support AJAX.");
      return null;
      }
}
       
      // Change the value of the outputText field}

function setCheck(){
	if(httpObject.readyState == 4){
	  
	document.getElementById('thischanges').innerHTML = httpObject.responseText;

	}

}


function check(form_check){

	
	httpObject = getHTTPObject();

    if (httpObject != null) {
		httpObject.open("GET", "check.php?formid=" + document.getElementById('form_check').value, true);
      	httpObject.send(null);
     	httpObject.onreadystatechange = setCheck;
	}
}

</script>

then in your check.php or whatever language you are using you would set up all the HTML/Form code that you would want to return.
You can set this all up in a variable and then apply that to a DIV with an ID or anything else you fancy.

If you want more information drop me an email and I will give you a detailed breakdown of the code.

You should also have a look at JQuery as this has been developed with the intention of making forms and data dynamic without reloading the page. It is a free program and it is getting more popular as people demand the functionality that you are looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.