robert323 Posted July 16, 2006 Share Posted July 16, 2006 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!-Robert Link to comment https://forums.phpfreaks.com/topic/14801-getting-current-text-from-html-choosebox/ Share on other sites More sharing options...
rab Posted July 16, 2006 Share Posted July 16, 2006 [code]<form action="test.php" method="post"><input type="checkbox" name="bike">I have a bike<br><input type="checkbox" name="car">I have a car<br/><input type="submit" /></form>[/code][code]<?phpif($_POST["bike"] == TRUE) {..}?>[/code]remember you can always see what is in the $_POST array using print_r($_POST); Link to comment https://forums.phpfreaks.com/topic/14801-getting-current-text-from-html-choosebox/#findComment-59114 Share on other sites More sharing options...
AndyB Posted July 16, 2006 Share Posted July 16, 2006 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:[code]<?php$color = $_POST['color'];echo "You chose ". $color; // trivial output?>[/code] Link to comment https://forums.phpfreaks.com/topic/14801-getting-current-text-from-html-choosebox/#findComment-59115 Share on other sites More sharing options...
robert323 Posted July 17, 2006 Author Share Posted July 17, 2006 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></select>ok, and here's part of my PHP$start_hour = $_POST['start_hour'];echo $start_hour;**end codeIs there anything horribly, horribly obvious that I'm missing!? Sorry for being so annoying! Link to comment https://forums.phpfreaks.com/topic/14801-getting-current-text-from-html-choosebox/#findComment-59117 Share on other sites More sharing options...
True`Logic Posted July 17, 2006 Share Posted July 17, 2006 [code]<?phpif(!isset($_GET["color"])) {echo "<script>function Change() {document.getElementById(\"moo\").innerHTML=document.getElementById(\"color\").value}</script><form><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></select><input type=submit value=chose!></form><span id=moo>Orange</span>";}else {echo "You chose: " . $_GET["color"];}?>[/code]this does both live, and after submitting :) Link to comment https://forums.phpfreaks.com/topic/14801-getting-current-text-from-html-choosebox/#findComment-59176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.