TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-28-2008, 10:46 PM   #1 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default Radio buttons - fetching query?

Hi all.. Here's my scenario.

four radio buttons
Each have own data in database
When user make hes choose, data would change automaticlly in that page..

eh.. I hope you understand what I'm after? Hard to explain while english isn't my home language! ;)

Don't know much javascript/frameworks so thats why I here (again and again.. ;))

I'm already using prototype in my page so, if there is sollution that would be great! But doesn't have to.. I don't know what to look so even if someone knows something similar, could you share link or something so I could go and look.

Thanks for all help!
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
Old 03-29-2008, 04:49 AM   #2 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

Try this link - many, many great ajax starter tutorials that should push you in the right direction:

Tutorials Round-Up: Ajax, CSS, PHP and More | Tutorials | Smashing Magazine
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
Old 03-29-2008, 11:48 AM   #3 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default

Thanks serversphere, I'm familiar that page quite a bit! ;)

Anyway, I manage to get some help from another page and here's result. (if someone needs?!)

Ajax.js:
Code:
var rdiv;
var xmlHttp;
var cb;
function request (url, div, parameters, callback)
{

	if(xmlHttp)
	{
		//alert("aboting current xmlhttp");
		//xmlHttpd.abort();
	}
	rdiv = div;
	var queryString = url + "?" + parameters;
	cb = callback;

	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", queryString, true);
	xmlHttp.send(null);
}

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

function handleStateChange()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			parseResults();
		}
	}
}
function parseResults()
{

	document.getElementById(rdiv).innerHTML = xmlHttp.responseText;
	if(cb) cb();

}
Code:
function fetchQueryPage(pid)
{
    request("/doquery.php", "doquery_box", "id=" + pid)
}
Place div whit class name "doquery_box" page where you are using this. And call fetchQueryPage function onClick event in your radio buttons.

Code:
<input type="radio" name="myradio" onClick="fetchQueryPage(11);" />
and finally, in doquery.php you have your code ie.
PHP Code:

$pid 
$_GET['id'];

$q mysql_query("SELECT result FROM table WHERE id = '$pid'") or die(mysql_error());
$do mysql_fetch_array($q);

print(
"Here is your result:" $do['result']); 
Ok.. I'm happy now when finally got it BUT, now I have different problem.
How can I define that if one of those radio buttons are already checked when user arrive that page, then run that fetchQueryPage function?

Because I have option on different page when user can choose one of those radios.

Code:
if (radio.[i].checked == true)
{
  run that function whit that pid
}
else
{
  wait while user clicks one of those radios
}

Thanks for all help! =)
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
Old 03-29-2008, 01:20 PM   #4 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

Very nice! Just be sure to sanitize the ID passed to doquery.php or else it could be subject to sql injection.
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
Old 03-29-2008, 01:26 PM   #5 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default

Oh yes offcourse that was just example and type as was posted.. =)
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:09 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design