...

View Full Version : script wont echo this variable



Ranger56
01-07-2006, 02:18 AM
<!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;



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

Yusayoh
01-07-2006, 02:27 AM
Try making the value of the radio buttons the size. Like:


<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:

echo $_POST['formsize'];

Ranger56
01-07-2006, 02:30 AM
well i need what's echoed to be the variable anyways, but ill try what you said

Ranger56
01-07-2006, 02:39 AM
<!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?

Yusayoh
01-07-2006, 03:07 AM
Put in a submit button.

GO ILLINI
01-07-2006, 04:04 AM
or some submit thing in an onclick=""

Ranger56
01-07-2006, 04:21 AM
im trtying to get away from java script

GO ILLINI
01-07-2006, 04:46 AM
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

Ranger56
01-07-2006, 05:01 AM
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.

_Aerospace_Eng_
01-07-2006, 05:51 AM
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.

GO ILLINI
01-07-2006, 06:14 AM
thats what I was saying...(since the request was for no refresh)

felgall
01-07-2006, 10:01 PM
Only client side scripting (ie. Javascript) can update a web page without reloading it completely.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum