1,105,556 Community Members

How to load Radio button with value from Database using JQUERY

Member Avatar
cigoL..:)
Light Poster
47 posts since Jul 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
0
 

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!


-cigoL

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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??

Member Avatar
cigoL..:)
Light Poster
47 posts since Jul 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
0
 

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
i.e
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 ..

Member Avatar
cigoL..:)
Light Poster
47 posts since Jul 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Question Answered as of 2 Years Ago by diafol
Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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");
while($d=mysql_fetch_assoc($r)){
	$x = explode(',',$d['output']);
	sort($x);
	$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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
	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;
	}
</script>
</head>
<body>
<form>
	<select id="me" onchange="showMe();">
    	<?php
			foreach($listarray as $item){
				echo "<option value=\"$item\">$item</option>";	
			}
		?>
    </select>

<div id="showradios">

</div>
...
</form>
</body>
</html>

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

Member Avatar
cigoL..:)
Light Poster
47 posts since Jul 2011
Reputation Points: -1 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 2 [?]
 
0
 

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 :)

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: