Paul_Bunyan Posted July 2, 2008 Share Posted July 2, 2008 Hello. I am attempting to make an update page where an admin can modify existing records. I am running into a problem when I create my drop down lists with php and I can't seem to find the error that I am making or a thread with the same problem. I am reading from an Oracle database and grabbing my record with the following code: <?php $select_doc = "SELECT total_jumps FROM mars_reports WHERE rec_id=".$rec_id; $doc = $pubs_db->Execute($select_doc) or die($pubs_db->ErrorMsg()); $com = $pubs_db->Execute("commit") or die($pubs_db->ErrorMsg()); ?> As a test I have been echoing out the results to make sure that I am reading successfully: <?php echo $doc->Fields('total_jumps'); ?> I get the expected value. However, when I try to create my dropdown list in my form with the correct value selected by default, it does not work. Here is the code I use w/in my form: <tr> <th align="left" valign="top" scope="row">Total Jumps: </th> <td align="left" valign="top"> <select name="total_jumps" id="total_jumps"> <option value="NA" <?php if($doc->Fields('total_jumps')=="NA") echo "selected"; ?>>Not applicable.</option> <option value="19" <?php if($doc->Fields('total_jumps')=="19") echo "selected"; ?>>< 20</option> <option value="21" <?php if($doc->Fields('total_jumps')=="21") echo "selected"; ?>>20 to 49</option> <option value="51" <?php if($doc->Fields('total_jumps')=="51") echo "selected"; ?>>50 to 99</option> <option value="101" <?php if($doc->Fields('total_jumps')=="101") echo "selected"; ?>>100 to 149</option> <option value="151" <?php if($doc->Fields('total_jumps')=="151") echo "selected"; ?>>150 to 199</option> <option value="201" <?php if($doc->Fields('total_jumps')=="201") echo "selected"; ?>>200 to 249</option> <option value="251" <?php if($doc->Fields('total_jumps')=="251") echo "selected"; ?> >250 to 299</option> <option value="300" <?php if($doc->Fields('total_jumps')== "300") echo "selected"; ?>>> 299</option> </select> </td> <td align="left" valign="top">*ND</td> </tr> Thank you for any insight you may have into my problem. Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/ Share on other sites More sharing options...
DarkWater Posted July 2, 2008 Share Posted July 2, 2008 What do you mean by "it does not work"? Does it error you? Does it just not select the proper one? Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580065 Share on other sites More sharing options...
mbeals Posted July 2, 2008 Share Posted July 2, 2008 i have fought with this in the past too. try changing echo "selected" to echo 'selected="selected"'; sounds stupid, but i've had that exact issue break select boxes on me. Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580081 Share on other sites More sharing options...
Jabop Posted July 2, 2008 Share Posted July 2, 2008 selected="selected" selected="yes" selected="true" all work Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580085 Share on other sites More sharing options...
Paul_Bunyan Posted July 2, 2008 Author Share Posted July 2, 2008 What do you mean by "it does not work"? Does it error you? Does it just not select the proper one? Ah, sorry I wasn't specific. It doesn't select the correct option. It always selects, "Not Applicable." . i have fought with this in the past too. try changing echo "selected" to echo 'selected="selected"'; sounds stupid, but i've had that exact issue break select boxes on me. I tried your solution mbeals, but I still can't get the right option to be selected. I also tried all of the variations given by Jabop. Thanks for the help so far Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580148 Share on other sites More sharing options...
mbeals Posted July 2, 2008 Share Posted July 2, 2008 look at the source the script is producing and see what it is actually printing. Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580190 Share on other sites More sharing options...
Paul_Bunyan Posted July 2, 2008 Author Share Posted July 2, 2008 Here is the source that is generated: <tr> <th align="left" valign="top" scope="row">Total Jumps: </th> <td align="left" valign="top"> <select name="total_jumps" id="total_jumps"> <option value="NA" >Not applicable.</option> <option value="19" >< 20</option> <option value="21" >20 to 49</option> <option value="51" >50 to 99</option> <option value="101" >100 to 149</option> <option value="151" >150 to 199</option> <option value="201" >200 to 249</option> <option value="251" >250 to 299</option> <option value="300" >> 299</option> </select> </td> <td align="left" valign="top">*ND</td> </tr> Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580192 Share on other sites More sharing options...
mbeals Posted July 2, 2008 Share Posted July 2, 2008 it looks like there is something wrong with it processing $doc->Fields('total_jumps') or comparing it to your value. <tr> <th align="left" valign="top" scope="row">Total Jumps: </th> <td align="left" valign="top"> <select name="total_jumps" id="total_jumps"> <option value="NA" <?php if($doc->Fields('total_jumps')=="NA") echo "selected"; ?>>Not applicable. <?=$doc->Fields('total_jumps')?></option> <option value="19" <?php if($doc->Fields('total_jumps')=="19") echo "selected"; ?>>< 20 <?=$doc->Fields('total_jumps')?></option> <option value="21" <?php if($doc->Fields('total_jumps')=="21") echo "selected"; ?>>20 to 49 <?=$doc->Fields('total_jumps')?></option> <option value="51" <?php if($doc->Fields('total_jumps')=="51") echo "selected"; ?>>50 to 99 <?=$doc->Fields('total_jumps')?></option> <option value="101" <?php if($doc->Fields('total_jumps')=="101") echo "selected"; ?>>100 to 149 <?=$doc->Fields('total_jumps')?></option> <option value="151" <?php if($doc->Fields('total_jumps')=="151") echo "selected"; ?>>150 to 199 <?=$doc->Fields('total_jumps')?></option> <option value="201" <?php if($doc->Fields('total_jumps')=="201") echo "selected"; ?>>200 to 249 <?=$doc->Fields('total_jumps')?></option> <option value="251" <?php if($doc->Fields('total_jumps')=="251") echo "selected"; ?> >250 to 299 <?=$doc->Fields('total_jumps')?></option> <option value="300" <?php if($doc->Fields('total_jumps')== "300") echo "selected"; ?>>> 299 <?=$doc->Fields('total_jumps')?></option> </select> </td> <td align="left" valign="top">*ND</td> </tr> try that and see if it is returning the expected values. you also have an extra > in the last option. Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580197 Share on other sites More sharing options...
Paul_Bunyan Posted July 2, 2008 Author Share Posted July 2, 2008 Interesting results. So, the expected value is being echoed. But the correct drop down option is not being selected. So for example, when I select a record with the value 151, the drop down box shows the default value as "Not Applicable. 151" Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580204 Share on other sites More sharing options...
Paul_Bunyan Posted July 2, 2008 Author Share Posted July 2, 2008 Ah ok. I figured it out and I feel pretty dumb. The table in Oracle was a char(20) so the value was being stored with the extra whitespaces included. So 151 was stored as "151 ". Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580222 Share on other sites More sharing options...
mbeals Posted July 2, 2008 Share Posted July 2, 2008 haha, no problem. Don't feel bad, I've spent 2+ days trying to figure something out that turned out to be a whitespace issue. Link to comment https://forums.phpfreaks.com/topic/112927-drop-down-box-not-selecting-the-correct-default-value/#findComment-580225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.