954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Am not able to get a radio button selection to display in output

Temperature Conversion

The temperature you entered was <?php echo $_POST["tempEntry"]; ?>.

That is equivalent to <?php printf("%2.0f",$convCelTemp) ?> <?php echo $celconvMsg; ?>.

Return to Temperature Page

venetian_jigsaw
Newbie Poster
15 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

(1) Allows a user to enter a temperature and based on a selection from a radio button, converts the temperature to either celcius or fahrenheit.

(2) Writes the output to another php page.

My problem lies when selecting either the celcius or fahrenheit radio button. How do I get either, based on selection, to write to the output? Do I need to write if/else statment or can I use case/switch?

I don't see your form, but sounds like either case or if else will do the trick. Imagining you are sending a radio button called temp_format
Use Celcius
Use Farenheit

Then in your php page you would just

if ($temp_format == 'c') { // or use the "proper" $_POST["temp_format"]

// show the celcius version

} else {

// show the farenheit version
}

You're not asking us to do your homework are you? ;)

barnamos
Junior Poster in Training
50 posts since Mar 2005
Reputation Points: 15
Solved Threads: 0
 

Temperature Conversion



Enter a temperature:

Convert to Celcius
Convert to Fahrenheit

venetian_jigsaw
Newbie Poster
15 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

[HTML] Convert to Celcius
Convert to Fahrenheit

[/HTML]

The above means that you need to look for the post variable 'temp' like so:

[PHP]$convTemp = $_POST['temp'];[/PHP]

Then whenever you reference $convTemp:

[PHP]if($convTemp == 'Fahrenheit') { do stuff }
if($convTemp == 'Celcius') {do stuff }
if(($convTemp != 'Fahrenheit') && ($convTemp !='Celcius')) { die('we have a big problem!'); }[/PHP]

you will see Fahrenheit or Celcius, whichever the user picked.

If I remember correctly I read somewhere (can't remember where) that if-then-else statements are faster than case-switch statements, but as you are only dealing with 2 options it probably doesn't matter which you use as long as it works.

DanceInstructor
Posting Whiz
368 posts since Feb 2005
Reputation Points: 17
Solved Threads: 14
 

Well, thanks to both of you, barnamos and Dance Instructor. Based on what you provided me with, I was able to figure out what I needed to do. I tested and it worked!!! Like I side, sometimes your brain goes in other directions. Actually, I sat down and wrote out my vars, etc, and then it came to me where each var needed to go in the if/else statements and then w/in my php tags.

Happy trails and again, many thanks!!!

venetian_jigsaw

venetian_jigsaw
Newbie Poster
15 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You