Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts

    script wont echo this variable

    PHP Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1">
    <title>Font Sizer</title>
    </head>
    <body>
    <?php

    switch($_POST['fontsize']){
        case 
    'tw':
           
    $fontsize '12px';
           break;
        case 
    'fo':
           
    $fontsize '14px';
           break;
        case 
    'si':
           
    $fontsize '16px';
           break;
        case 
    'twen':
            
    $fontsize '18px';
            break;
         default:
            
    $fontsize '12px';
    }     
         echo 
    $fontsize;
    ?>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="radio" value="tw" name="fontsize"><label>12px</label>
    <input type="radio" value="fo" name="fontsize"><label>14px</label>
    <input type="radio" value="si" name="fontsize"><label>16px</label>
    <input type="radio" value="twen" name="fontsize"><label>18px</label>
    </form>
    </body>
    </html>
    It won't echo $fontsize;

    Edit:

    it will echo fontsize, but only the default, it doesnt change if you select any of the radio buttons.

    Last edited by Ranger56; 01-07-2006 at 02:20 AM.

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try making the value of the radio buttons the size. Like:
    Code:
    <input type=radio value=5 name=formsize>5px<br>
    <input type=radio value=20 name=formsize>20px<br>
    Something like that. And take out the switch and put:
    Code:
    echo $_POST['formsize'];
    |||||||||||||||||||||||||||||||||

  • #3
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well i need what's echoed to be the variable anyways, but ill try what you said

  • #4
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <style type="text/css">
    <!--
    <?php
    $css 
    'p{'"\n";
    $css .= 'font-size:' $_POST['fontsize'] . "px; \n";
    $css .= '}';
    echo 
    $css;
    ?>
    -->
    </style>
    <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1">
    <title>Font Sizer</title>
    </head>
    <body>
    <p>
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras massa. Nam aliquam. Fusce id ipsum. Suspendisse vestibulum tristique dolor. Vivamus non nulla eu velit venenatis ultrices. Donec urna turpis, ultrices ac, fringilla vel, tincidunt eget, orci. Fusce adipiscing ante sed elit. Sed auctor elementum purus. Nunc sed tortor. Sed eget diam. In sed neque. Pellentesque volutpat auctor nisi. Sed blandit porta mi. Duis risus sem, scelerisque a, elementum sit amet, dignissim sit amet, urna. Nunc enim. Etiam vehicula scelerisque tortor. Mauris egestas, augue et fringilla elementum, felis risus porttitor pede, condimentum sagittis mi nulla nec lorem.
    </p>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="submit" value="12" name="fontsize">
    <input type="submit" value="14" name="fontsize">
    <input type="submit" value="16" name="fontsize">
    <input type="submit" value="20" name="fontsize">
    </form>
    </body>
    </html>
    That works, but is there any way to do it without reloading the page?

  • #5
    New Coder
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Put in a submit button.
    |||||||||||||||||||||||||||||||||

  • #6
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    or some submit thing in an onclick=""
    Why not thank me?

    http://adamsworld.name

  • #7
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im trtying to get away from java script

  • #8
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    But it has so many things that php doesnt! (even though I started out learning js but now use it about once every 2 months...) Client side and server side that makes all the difference. If you want things to happen for the visitor... it needs to be client side.
    Just my 2 cents...



    ILLINI
    Why not thank me?

    http://adamsworld.name

  • #9
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by GO ILLINI
    But it has so many things that php doesnt! (even though I started out learning js but now use it about once every 2 months...) Client side and server side that makes all the difference. If you want things to happen for the visitor... it needs to be client side.
    Just my 2 cents...



    ILLINI
    I know, and JS would be best for this, but im jsut trying to make something that will work for people with JS disabled.

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can't. You need to post back to the server since php IS a server side language. If want to echo something without refreshing you need to use javascript, possibly some form of ajax that can communicate with the server to an extent.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    thats what I was saying...(since the request was for no refresh)
    Why not thank me?

    http://adamsworld.name

  • #12
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,609
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Only client side scripting (ie. Javascript) can update a web page without reloading it completely.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •