Click here to Skip to main content
15,881,455 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: Radio Buttons Pin
thebiostyle28-Dec-09 10:34
thebiostyle28-Dec-09 10:34 
GeneralRe: Radio Buttons Pin
cjoki29-Dec-09 4:32
cjoki29-Dec-09 4:32 
GeneralRe: Radio Buttons Pin
abushahin31-Dec-09 7:45
abushahin31-Dec-09 7:45 
AnswerRe: Radio Buttons (long answer) Pin
enhzflep29-Dec-09 14:14
enhzflep29-Dec-09 14:14 
GeneralRe: Radio Buttons (long answer) Pin
thebiostyle30-Dec-09 7:31
thebiostyle30-Dec-09 7:31 
GeneralRe: Radio Buttons (long answer) Pin
enhzflep30-Dec-09 11:56
enhzflep30-Dec-09 11:56 
GeneralRe: Radio Buttons (long answer) Pin
thebiostyle30-Dec-09 12:17
thebiostyle30-Dec-09 12:17 
GeneralRe: Radio Buttons Pin
enhzflep30-Dec-09 13:20
enhzflep30-Dec-09 13:20 
Yeah, not a massive,massive fan of dreamweaver myself, though for laying out div-tags and some certain operations, it really does suit me.
It's much easier to get it to spit out a few tags then modify in code than it is to remember them all for me.
Tried a bunch of editors, though really none have made me take the effort of making them usb-portable or able to be easily used in linux.
(Done both with dw)
Have you tried Notepad++[^]?

That said, I forget who, but somebody suggested the use of Hidden Fields. These are exactly what I used.
The way I saw it - there were two options for getting the value into the hidden field ready for form-submittal.

(1) Modify the doClick function, so that it updated the hidden field anytime a radio-button was clicked

or

(2) Use the onsubmit handler of the form to grab the value for me, before submitting the form.

I opted for #2, since that keeps the code 'cleaner' and is a more re-usable method.


Here you go:

resultsPage.php
<!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>
</head>

<body>
Your preferred browser is: <?php echo $_POST["preferredBrowser"]; ?>
</body>
</html>


index.php
<!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 type="text/javascript">
function byId(e){return document.getElementById(e);}
function byName(e){return document.getElementsByName(e);}
function changeState(el, stateMod){el.state ^= stateMod;}

function updateImg(el)
{
	imgs = Array("rb1.png", "rb2.png", "rb3.png", "rb4.png");
	el.src = imgs[el.state];
}

function drawRadioGroup(groupName)
{
	var elements, i, count;
	elements = byName(groupName);
	count = elements.length;
	for (i=0; i<count; i++)
		updateImg(elements[i]);
}

function doClick(el)
{
	var elements, i, count;
	elements = byName(el.name);
	for (i=0; i<elements.length; i++)
	{
		elements[i].state &= 1;
		updateImg(elements[i]);
	}
	el.state |= 2;
	updateImg(el);
}

function getRadioGroupValue(groupName)
{	
	result = "none selected";
	elements = byName(groupName);
	count = elements.length;
	for (i=0; i<count; i++)
	{
		if (elements[i].state >= 2)
			result = elements[i].value;
	}
	return result;
}

function addRadioButton(groupName, optionValue, labelValue, tgtContainer)
{
	lblObj = document.createElement("label");
	lblText = document.createTextNode(labelValue);
	
	// create the miage object
	imgObj = document.createElement("img");
	imgObj.name = groupName;
	imgObj.src = "rb1.png";
	imgObj.width = "12";
	imgObj.height = "12";
	imgObj.value = optionValue;
	imgObj.onmouseout =  function(){ changeState(this, 1); updateImg(this); }  //onmouseout="changeState(this, 1); updateImg(this)"
	imgObj.onmouseover = function(){ changeState(this, 1); updateImg(this); }
	imgObj.onclick = function(){doClick(this);}
	
	lblObj.appendChild(imgObj);		// add the image to the label object
	lblObj.appendChild(lblText);	// add the label text after the img - text appears to the right of the image

	tgtContainer.appendChild(lblObj);	// add the label object to the target container

	// add the img object to the target container
	newLineObj = document.createElement("br");	// and add a new-line, ready for the next item to be added
	tgtContainer.appendChild(newLineObj);
}

function createGroup(groupName)
{
	choices = Array("Firefox", "Chrome", "Navigator", "Safari", "Opera", "Internet Explorer");
	for (i=0; i<choices.length; i++)
		addRadioButton(groupName, choices[i], choices[i], byId("radioHolder"));
}

function getHiddenValue()
{
	chosenValue = getRadioGroupValue("radioGroup1");
	byId("pollChoice").value = chosenValue;
	return 1;
}

function test2(){alert(getRadioGroupValue("radioGroup1"));}
</script>
</head>
<body onload="createGroup('radioGroup1', 10);">
<h3>What is your Preferred browser?</h3>
	<div id = "radioHolder"></div>
    <form id="dummyForm" action="resultsPage.php" method="post" onsubmit="getHiddenValue();">
        <input type="hidden" name="preferredBrowser" id="pollChoice" value=""/>
    	<input type="submit" value="Vote"/><br/>
</body>
</html>

Cool | :cool:
GeneralRe: Radio Buttons Pin
thebiostyle30-Dec-09 13:34
thebiostyle30-Dec-09 13:34 
GeneralRe: Radio Buttons [modified x2] Pin
enhzflep30-Dec-09 13:41
enhzflep30-Dec-09 13:41 
GeneralRe: Radio Buttons Pin
thebiostyle30-Dec-09 13:59
thebiostyle30-Dec-09 13:59 
GeneralRe: Radio Buttons Pin
enhzflep31-Dec-09 7:04
enhzflep31-Dec-09 7:04 
GeneralRe: Radio Buttons Pin
thebiostyle31-Dec-09 7:13
thebiostyle31-Dec-09 7:13 
GeneralRe: Radio Buttons Pin
enhzflep31-Dec-09 13:05
enhzflep31-Dec-09 13:05 
GeneralRe: Radio Buttons Pin
thebiostyle31-Dec-09 18:13
thebiostyle31-Dec-09 18:13 
GeneralRe: Radio Buttons [modified] Pin
enhzflep31-Dec-09 19:41
enhzflep31-Dec-09 19:41 
GeneralRe: Radio Buttons Pin
thebiostyle31-Dec-09 21:44
thebiostyle31-Dec-09 21:44 
QuestionFind the differences betwween two arrays Pin
Marc Firth24-Dec-09 0:51
Marc Firth24-Dec-09 0:51 
AnswerRe: Find the differences betwween two arrays Pin
Luc Pattyn28-Dec-09 10:43
sitebuilderLuc Pattyn28-Dec-09 10:43 
QuestionHow to use postback in php Pin
sarang_k23-Dec-09 22:28
sarang_k23-Dec-09 22:28 
AnswerRe: How to use postback in php Pin
Marc Firth24-Dec-09 1:25
Marc Firth24-Dec-09 1:25 
Questionwarning message Pin
kamalesh574323-Dec-09 15:27
kamalesh574323-Dec-09 15:27 
AnswerRe: warning message Pin
Marc Firth24-Dec-09 1:27
Marc Firth24-Dec-09 1:27 
QuestionSTL vector trouble Pin
Daniel 'Tak' M.22-Dec-09 5:27
Daniel 'Tak' M.22-Dec-09 5:27 
Questionhelp with imap_search function Pin
cjoki21-Dec-09 7:08
cjoki21-Dec-09 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.