#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    22
    Rep Power
    0

    Smile changing css style color with switch


    Ok, this should be easy for you guys here.

    This is what I'm trying to do :

    -create a recursive page

    -page contains 3 radio buttons

    -buttons allow for choice between colors: green, blue, red.

    -default choice is green font color (css style)

    -form should remember the selected choice (the rest of the page performs some addition problems)

    -can't use cookies only the switch function to change the font color (css style)

    -no external css files

    Here's what I have. I know I'm making some mistakes, just don't know how to fix them.


    Thank you.


    -----------------
    The second part of my question is of low priority :

    What's the best text editor to use for the Mac? I was using BBEDIT and began to see some weird characters on some servers.

    Are there any text editors that color the text (different colors for diff. attributes) and also show line#'s (for the mac osx?)


    -----------------clipping starts here----------------

    <html>
    <head>
    <title></title>
    <body style="font-family:Arial, Helvetica, sans-serif; color: green;">
    </table>
    <tr>
    <td>
    <form name="stylecolor" method=POST" action asgn_2j.php">

    Green
    <input type="radio" name="style" value="green">

    Blue
    <input type="radio" name="style" value="blue">

    Red
    <input type="radio" name="style" value="red">

    <INPUT TYPE=HIDDEN NAME=stylecolor VALUE=true>

    <INPUT TYPE=submit NAME="SUBMIT" VALUE="Submit">

    <?
    $stylecolor=$HTTP_POST_VARS['stylecolor'];

    switch($stylecolor)
    {
    case 'green
    echo '(<body style="font-family:Arial, Helvetica, sans-serif; color: green;">)' ;

    case 'blue'
    echo '(<body style="font-family:Arial, Helvetica, sans-serif; color: blue;">)' ;

    case 'red'
    echo '(<body style="font-family:Arial, Helvetica, sans-serif; color: red;">)' ;

    default:
    echo 'you didn't choose' ;
    break;

    }
    ?>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Posts
    790
    Rep Power
    15
    dmonk,

    There's no need to use a switch structure to do what you want to do. There were a few problems with your code. Take a look at the modified code below and compare to your code to see the changes that were made. Hopefully, that will explain a few things.

    I'm not sure what you were trying to do with the hidden field but it looks like that's what you were trying to evaluate in your switch. However, you should be checking the value of the radio buttons. Putting [] after the name of the radio buttons makes PHP view them as an array. Since they are radio buttons, only one is going to have a value set so all you need to evaluate is the first element of the style array ( $_POST['style'][0]) to get the selected color.

    The if(isset($_POST['style']) checks to see if the form has been submitted. If it has then the value of the selected radio button is used for the style color. If the form has not been submitted, the default color is used (the else{}) portion of the code.

    Hope this all makes sense and helps out a bit.

    PHP Code:
    <html>
    <head>
    <title></title>
    </head>
    <?php
    if(isset($_POST['style'])){
    $stylecolor=$_POST['style'][0];
    echo 
    "<body style='color:$stylecolor'>";
    }
    else
    {
        echo 
    "<body style='color:green'>";
    }
    ?>

    </table>
    <tr>
    <td>
    <form name="stylecolor" method="POST" action="asgn_2j.php">

    Green
    <input type="radio" name="style[]" value="green">

    Blue
    <input type="radio" name="style[]" value="blue">

    Red
    <input type="radio" name="style[]" value="red">

    <INPUT TYPE=submit NAME="SUBMIT" VALUE="Submit">

    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    22
    Rep Power
    0

    Thanks


    Than you for the help micros_bytes, I'll give it a try.

    -Dan

IMN logo majestic logo threadwatch logo seochat tools logo