Jump to content

Drop down box not selecting the correct default value.


Paul_Bunyan

Recommended Posts

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

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

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

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

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
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.