Jump to content

Get Form Listbox Text Value


maxhugen

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.