Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

input type=radio question

Posted on 2001-08-04
3
Medium Priority
?
283 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 120 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

824 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