Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX Checkbox

Status
Not open for further replies.

kyern

Programmer
Mar 30, 2006
36
US
I have a large form that is used to enable / disable several categories of a report generator I am creating. Each category has a simple checkbox. I would really like to find a way to ajax enable this application. I am still extremely new to ajax. I figure to do this I need to make each checkbox have a unique name then somehow do a onclick event on the checkbox that does the ajax call. How do i do the ajax call though? Any insight would be appreciated.

David
 
If you were using the prototype library:
Code:
		<script type="text/javascript" language="javascript" charset="utf-8">
			// <![CDATA[
		var checkList = Form.getElements("myform");
		checkList.each(function(el) {
				Event.observe(el, "change", function() {
				new Ajax.Request('yourscript.asp', {
				  method: "post",
				  postBody: el.name + '=' + $F(el),
				  asynchronous: true
				});       
				});
		}.bind(this));
			// ]]>
		</script>

Let us know your results!

X
 
Hi Kyern,

Prototype is very popular, and Xagte's suggestion looks good.

Another alternative is to use a library like the lightweight jQuery.

Sample jQuery code for your script might simply be:
Code:
$("#category1").click(function(){
   $.post("config_report.php", { report: "financials" } );
});

...where "category1" would be the id of one of your checkboxes, and "config_report.php" (or ASP, or what have you) would process the info (a parameter called "report" with a value of "financials") immediately when the checkbox is ticked.

This is a simple example (and not tested), used to demonstrate the code. Check out for more information, documentation, tutorials and demos. covers core AJAX-specific features.


Good luck,
--RHYNO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top