Radio buttons anf IF statements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fire Juggler

    Radio buttons anf IF statements

    On a form, i have
    <label><input name="radiogrou p" type="radio" value="Technica l">
    Technical</label>
    <label><input name="radiogrou p" type="radio" value="Admin">
    Administrative</label>
    <label><input name="radiogrou p" type="radio" value="Site">
    Web-Site</label>
    <label><input name="radiogrou p" type="radio" value="General"
    checked>
    General</font></dd></label>

    then on another form i want an if statement
    like
    if ($radiogroup==" Admin")
    {
    $contact="email address";
    $subject="subje ct"l
    else
    {
    $contact="anoth eremailaddress" ;
    $subject="anoth ersubject";

    Is this correct, or how do i do an if statement including depending on what
    radio button is checked?

    thanks
    --
    Kathryn (Fire Juggler)




  • Alvaro G Vicario

    #2
    Re: Radio buttons anf IF statements

    *** Fire Juggler wrote/escribió (Tue, 22 Mar 2005 14:47:55 -0000):[color=blue]
    > if ($radiogroup==" Admin")
    > {
    > $contact="email address";
    > $subject="subje ct"l
    > else
    > {
    > $contact="anoth eremailaddress" ;
    > $subject="anoth ersubject";
    >
    > Is this correct, or how do i do an if statement including depending on what
    > radio button is checked?[/color]

    It's not portable since you're assuming that form variables will be
    imported as local variables. which is often not the case. Also, a switch
    normally provides clearer code in situations like this.

    <?

    switch($_POST['radiogroup']){ // Use $_GET if method="get"
    case 'Admin':
    $contact=...... ;
    $subject=...... ;
    break;

    case 'Site':
    $contact=...... ;
    $subject=...... ;
    break;

    case 'General':
    $contact=...... ;
    $subject=...... ;

    default:
    $contact='';
    $subject='';
    }

    ?>

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    Working...