newburcj Posted August 5, 2009 Share Posted August 5, 2009 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. Thanks! Charles Newbury Quote Link to comment Share on other sites More sharing options...
alexdemers Posted August 5, 2009 Share Posted August 5, 2009 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.