maxhugen Posted April 17, 2008 Share Posted April 17, 2008 I'm using PHP with html templates (CodeCharge Studio), and I have a form with some Listboxes. In another part of the Form, I need to show the Listbox 'display text' again - not the value. For example: <select id="ClientName"> <option value="1">Bruce</option> <option value="2" selected>Fred</option> <option value="3">Mary</option> </select> <select id="Job"> <option value="1">PHP</option> <option value="2">MySQL</option> <option value="3" selected>AJAX</option> </select> <p>You selected ClientName: [b]Fred[/b]</p> <p>You selected Job: [b]AJAX[/b]</p> I've worked out how to insert the Listbox value, but I don't know how I can insert the display text of the Listbox. Can anyone suggest how i should reference the Listbox display text in php please? MTIA Link to comment https://forums.phpfreaks.com/topic/101484-get-form-listbox-text-value/ Share on other sites More sharing options...
benphp Posted April 17, 2008 Share Posted April 17, 2008 Try this: <?php $clientName = $_POST['ClientName']; list($cName, $cNum) = split(",", $clientName); $jobName = $_POST['JobName']; list($jName, $jNum) = split(",", $jobName); ?> <form action="test.php" method="post"> <select name="ClientName[]"> <option value="1,Bruce">Bruce</option> <option value="2,Fred" selected>Fred</option> <option value="3,Mary">Mary</option> </select> <select name="JobName[]"> <option value="1,PHP">PHP</option> <option value="2,MySQL">MySQL</option> <option value="3,AJAX" selected>AJAX</option> </select> </form> <?php print "<p>You selected ClientName: $cName (ID: $cNum)</p>"; print "<p>You selected Job: $jName (ID: $jNum)</p>"; ?> Link to comment https://forums.phpfreaks.com/topic/101484-get-form-listbox-text-value/#findComment-519124 Share on other sites More sharing options...
maxhugen Posted April 17, 2008 Author Share Posted April 17, 2008 Thanks, I'll try that. Link to comment https://forums.phpfreaks.com/topic/101484-get-form-listbox-text-value/#findComment-519154 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.