Jump to content

Extracting a Label from a from list/menu populated bt a recordset.


newburcj

Recommended Posts

I'm using DW CS4 and within a form I have a list that's populated dynamically from a recordset. The Label part of the form contains a person's name and the value part contain their table id number. The code looks like this:

 

<select name="vVol_id" id="vVol_id" size="20">

  <?php

do { 

?>

  <option value="<?php echo $row_getVolunteer['vol_id']?>"><?php echo $row_getVolunteer['full_name']?></option>

  <?php

} while ($row_getVolunteer = mysql_fetch_assoc($getVolunteer));

  $rows = mysql_num_rows($getVolunteer);

  if($rows > 0) {

      mysql_data_seek($getVolunteer, 0);

  $row_getVolunteer = mysql_fetch_assoc($getVolunteer);

  }

?>

</select>

 

Selecting a persons name will return their table ID number which is user to be inserted in yet another table. My problem is that I also need to return the persons name which is in the selected Label. This too is used. I'm sure there must be a simple way to return the selected name into a variable so any coding suggestions would really be appreciated.  :facewall:

 

Thanks!

 

Charles Newbury

 

Link to comment
Share on other sites

Hey,

 

unfortunately this cannot be possible. The only things returned from forms submition is the value of a named element (select, input, textarea). In this case, the only thing returned is, you're correct, the ID of the person.

 

Now there's 2 options.

 

First, once your form has been submitted, you can get the value of the select: $_GET['vVol_id'] (obviously) and query your database to get the person's name.

 

The other option is to do it with JavaScript. Create a hidden input element in HTML: <input id="vVol_name" type="hidden" name="vVol_name" value="" /> and when you submit the form, fill in the value with the selected name of the <select> element. Now in PHP you can do: $_GET['vVol_name']

 

For the second option, if you are using jQuery (I'm more fluid in that framework):

 

<script type="text/javascript">
$('form#myForm').submit(function(){
    var personName = $('select#vVol_id :selected').text();
    $('input#vVol_name').attr('value', personName);
    return true;
});
<script>

 

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.