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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio button problem 1

Status
Not open for further replies.

overyde

Programmer
Joined
May 27, 2003
Messages
226
Location
ZA
Hi,
I need to pump info back into a form if a user needs to modify a record.

I know that
<input type=\&quot;text\&quot; name=\&quot;vname\&quot; value=\&quot;$vname\&quot;>
works for a text box...

but how do I get the correct radio button to be checked i.e.

<input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;1\&quot;>Opt1<br>
<input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;2\&quot;>Opt2<br>


Reality is built on a foundation of dreams.
 
Since what you are asking is basically a HTML question, here's what to do:
Code:
// checked
<input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;1\&quot; checked=\&quot;checked\&quot; />Opt1<br />

// unchecked
<input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;2\&quot; />Opt2<br />
Hope it helps.
 
No, that's not going to help.

I'm looking more at:

if (icon1 == &quot;1&quot;)
{print &quot;<input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;1\&quot; checked=\&quot;checked\&quot;>Opt1<br>&quot;;
}
else
{print &quot;<input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;2\&quot;>Opt2<br>&quot;;
}

The problem here is that there is 4 options and 4 icon fields which means I have to do this 16 times which is going to be far too heavy too load quickly.

Any other ideas?

Reality is built on a foundation of dreams.
 
make it a select list . radio buttons are nice for yes and no but I use select lists in stead when I need more options.

but 4x4 is not that heavy ;)
 
Code:
echo &quot;<tr><td><input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;1\&quot; &quot;;
if (icon1 == &quot;1&quot;) {echo &quot; CHECKED &quot;;}
echo &quot;>Opt1</td></tr>&quot;;

echo &quot;<tr><td><input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;2\&quot; &quot;;
if (icon1 == &quot;2&quot;) {echo &quot; CHECKED &quot;;}
echo &quot;>Opt2</td></tr>&quot;;

echo &quot;<tr><td><input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;3\&quot; &quot;;
if (icon1 == &quot;3&quot;) {echo &quot; CHECKED &quot;;}
echo &quot;>Opt3</td></tr>&quot;;

echo &quot;<tr><td><input type=\&quot;radio\&quot; name=\&quot;icon1\&quot; value=\&quot;4\&quot; &quot;;
if (icon1 == &quot;4&quot;) {echo &quot; CHECKED &quot;;}
echo &quot;>Opt4</td></tr>&quot;;

perhaps something like this is easier.

but you can also generate above code dynamicaly if you have all the possible values in a table

here is an example I use for the checkbox option

Code:
$query=&quot;SELECT * from clienttypetable order by cltdescr&quot;;
$rsclt=mysql_query($query,$conn);
$list = mysql_num_rows($rsclt); 
while($i < $list)	{
$row = mysql_fetch_array($rsclt); 
$cltid=$row[&quot;cltid&quot;];
$cltdescr=$row[&quot;cltdescr&quot;];
   echo &quot;<tr><td>$cltdescr</td><td><INPUT TYPE=checkbox name=cltype[$i] value=\&quot;$cltdescr\&quot;&quot;;
	if (stristr($cltype,$cltdescr)) {echo &quot; CHECKED &quot;;}
   echo &quot;></td></tr>&quot;;
$i++;
}

cltdescr has values like 'a','b','c','d','e'
cltype contains the checked values in a single string like &quot;a;b;d;e&quot;
with this query a,b,d,e will be checked and c will remain unchecked


 
Hos2,
That is a much easier way to do it! Thanks!

Reality is built on a foundation of dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top