Jump to content


getting current text from HTML choosebox

  • Please log in to reply
4 replies to this topic

#1 robert323

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 July 2006 - 11:44 PM

Hi all-
I'm sorry about asking such a trivial and dumb question, but I've looked around in several places, and I can't find the answer.

I'm trying to refference the current text contained in an HTML choosebox.
So say that i've got a choosebox called colour, with the options red, green, orange and blue.

Say someone selects the colour orange, and then hits a submit button.

I'm wondering how i would use a PHP form to echo Orange (or whatever value was selected from the choosebox).

Sorry for such a trivial question again! I'm really new to PHP, and any help is greatly appreciated!

Thanks so much!

#2 rab

  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 16 July 2006 - 11:56 PM

<form action="test.php" method="post">
<input type="checkbox" name="bike">
I have a bike
<input type="checkbox" name="car">
I have a car<br/>
<input type="submit" />

if($_POST["bike"] == TRUE) {
remember you can always see what is in the $_POST array using print_r($_POST);

#3 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 July 2006 - 11:58 PM

Assuming that the select name is color, that the form uses the POST method, and submits to a php script called whatever.php, then whatever.php needs to look like this:

$color = $_POST['color'];
echo "You chose ". $color; // trivial output

Legend has it that reading the manual never killed anyone.
My site

#4 robert323

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 July 2006 - 12:08 AM

I'm sure that works, but for some reason, there's some sort of error in my HTML (I think), and I can't really pinpoint it (I'm really new to both HTML and PHP)

So here's part of my HTML:

<jato:combobox name="start_hour"/>
<select name="start_hour">
<option value="" selected>Select Starting Hour</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>

ok, and here's part of my PHP

$start_hour = $_POST['start_hour'];
echo $start_hour;

**end code

Is there anything horribly, horribly obvious that I'm missing!? Sorry for being so annoying!

#5 True`Logic

  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 17 July 2006 - 04:58 AM

if(!isset($_GET["color"])) {
echo "
function Change() {
<select name=color onChange=\"Change()\">
<option value=Orange>Orange</option>
<option value=Red>Red</option>
<option value=Green>Green</option>
<option value=Blue>Blue</option>
<input type=submit value=chose!>
<span id=moo>Orange</span>
else {
echo "You chose: " . $_GET["color"];

this does both live, and after submitting :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users