Solved

input type=radio question

Posted on 2001-08-04
3
212 Views
Last Modified: 2006-11-17
Hello

I have a field in my table that is called "template" and i have a form with 3 radio buttons.

When the form is loaded it has to check a radio button depending on the value.
When i submit the form it has to write the value into my table field "template".

The code i try to use looks like:

echo "<input type=radio value=1 name=template ".if ($row[template]==1) echo "checked".">";
echo "<input type=radio value=2 name=template ".if ($row[template]==2) echo "checked".">";
echo "<input type=radio value=3 name=template ".if ($row[template]==3) echo "checked".">";

Why does this not work:

I always get a parse error
0
Comment
Question by:volvo
  • 2
3 Comments
 

Expert Comment

by:cynicz
ID: 6351968
change that to
echo "<input type=radio value=1 name=template" . ($row[template]==1) ? " checked" : "" . ">";

etc
0
 
LVL 15

Accepted Solution

by:
a.marsh earned 30 total points
ID: 6351981
Or why not make life easier and change the code to:

for($i = 1; $i < 4; $i++){
  echo "<input type=radio value=$i name=template";
  if($row[template] == $i) echo " checked";
  echo ">";
}


:o)

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6352809
Glad to have helped. :o)

Thanks for the A!

Ant
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now