Hello There,

Please Help, I have a form that generates data from database. i have to select value from a combobox so that i can see the value. but i wanted that data from database to be the value of the radio button. is that possible?I haven't started yet? can somebody give me a hint or a code snippet? i really need your help!Thanks!


Member Avatar for diafol

THat's difficult to follow. Could you explain that again?

1. you get data from DB based on what a form sends - OK
2. select value from combobox - ok - but what value are you talking about?
3. you want DB data to be the value of the radiobutton. What radio button??

The Values from Combobox is
i.e Array -> ('a',b','c','d');
now if i selected 'a'
it will run a query searching for 'a'
i.e "SELECT * from type_tb WHERE type ='a'"

then in radio button you will get the result from query
radio button1 value is 'ARMS'
radio button2 value is 'AIM'

well i can do it in simple PHP but i have it refresh it again, i wanted to do it dynamically . i'm new to jQuery since i'm stuck with other programming language for a long time ..

Thanks for your help i already figure this out thank you ! i'll mark it as solved!:)

Member Avatar for diafol

OK, that's relatively easy. Mind you, you could use 'false ajax' (my terminology) if you only have a handful of data items in the whole unfiltered dataset. That's when on page load, you get all the records from the SELECT * from type_tb type query and place the data into a js array. When you then select from the dropdown, it runs a js script to get the 'a' array items or the 'c' array items.

Just a thought. It saves going to the server and making DB server calls every time somebody selects something from the dropdown.

The down side of this is that any changes to the DB in the meantime will not be displayed on dropdown select. If your data is not going to be updated much, this should not be a great issue.

ANy use?

Member Avatar for diafol

As I posted my comment before it was solved (simultaneous post with your last one), I thought I should include my idea:

$listarray[] = 'Choose a letter...';
$r = mysql_query("SELECT SUBSTRING(`words`,1,1) AS letter, GROUP_CONCAT(`words`) AS `output` FROM table GROUP BY letter");
	$x = explode(',',$d['output']);
	$t[$d['letter']] = $x;
	$listarray[] = $d['letter'];
$myarray = json_encode($t);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
	var x = <?php echo $myarray;?>;
	function showMe(){
		var i = me.value;
		var str = '';
		if(x[i].length > 0){
			for(z = 0;z < x[i].length; z++){
				(z === 0) ? chk =  ' checked="checked"' : chk = "";
				str =  str + '<input id="' + x[i][z] + '" type="radio" name="help" ' + chk + ' /> <label for="' + x[i][z] + '">' + x[i][z] + '</label>';	
		document.getElementById('showradios').innerHTML = str;
	<select id="me" onchange="showMe();">
			foreach($listarray as $item){
				echo "<option value=\"$item\">$item</option>";	

<div id="showradios">


Somebody may find it useful or may even point out how to improve it.

Thank you sir, i got a hint from your "false ajax" terminology i use simple javascript. actually i make it very simple and easy to understand, for us "newbies", sir thank you for your time and code :)

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.