[ SOLVED ] select box not sending value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

[ SOLVED ] select box not sending value

Post by pickle »

Hi all,

I've got the weirdest thing here: I'm submitting a form with some select boxes in it. Regardless of what I select from those select boxes, their value doesn't get submitted. The variables get passed fine, but their values get wiped out.

I won't give you the full code for the form because there's a lot of superfluous stuff in it, but here's the select box generation code:

Code: Select all

if($show_time_fields)
{
 echo <<<PAGE
  <td>
   <select name = 'hrs_spent' id = 'hrs_spent'>
    <option value = ''></option>
PAGE;

 for($i = 1;$i <= 10;++$i)
 {
  echo "<option value = '$i'>$i</option>";
 }
 echo <<<PAGE
    </select>
   </td>
   <td>
    <select name = 'min_spent' id = 'min_spent'>
      <option value = ''></option>
PAGE;

 $minutes_list = array('5','10','15','20','30','40','45','50');
 foreach($minutes_list as $curr_min)
 {
  echo "<option value = '$curr_min'>$curr_min</option>";
 }
 echo <<<PAGE
     </select>
    </td>
PAGE;
  
}//if $show_time_fields == true
and here's the resulting XHTML:

Code: Select all

&lt;td&gt;
 &lt;select name=&quote;hrs_spent&quote; id=&quote;hrs_spent&quote;&gt;
  &lt;option value=&quote;&quote;&gt;&lt;/option&gt;
  &lt;option value=&quote;1&quote;&gt;1&lt;/option&gt;
  &lt;option value=&quote;2&quote;&gt;2&lt;/option&gt;
  &lt;option value=&quote;3&quote;&gt;3&lt;/option&gt;
  &lt;option value=&quote;4&quote;&gt;4&lt;/option&gt;
  &lt;option value=&quote;5&quote;&gt;5&lt;/option&gt;
  &lt;option value=&quote;6&quote;&gt;6&lt;/option&gt;
  &lt;option value=&quote;7&quote;&gt;7&lt;/option&gt;
  &lt;option value=&quote;8&quote;&gt;8&lt;/option&gt;
  &lt;option value=&quote;9&quote;&gt;9&lt;/option&gt;
  &lt;option value=&quote;10&quote;&gt;10&lt;/option&gt;
 &lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;
 &lt;select name=&quote;min_spent&quote; id=&quote;min_spent&quote;&gt;
  &lt;option value=&quote;&quote;&gt;&lt;/option&gt;
  &lt;option value=&quote;5&quote;&gt;5&lt;/option&gt;
  &lt;option value=&quote;10&quote;&gt;10&lt;/option&gt;
  &lt;option value=&quote;15&quote;&gt;15&lt;/option&gt;
  &lt;option value=&quote;20&quote;&gt;20&lt;/option&gt;
  &lt;option value=&quote;30&quote;&gt;30&lt;/option&gt;
  &lt;option value=&quote;40&quote;&gt;40&lt;/option&gt;
  &lt;option value=&quote;45&quote;&gt;45&lt;/option&gt;
  &lt;option value=&quote;50&quote;&gt;50&lt;/option&gt;
 &lt;/select&gt;
&lt;/td&gt;
Also, all the other elements in the form get submitted just fine - along with their values. It's just these two boxes. Any ideas? Thanks.
Last edited by pickle on Thu Jun 16, 2005 12:35 pm, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

One thing I dont understand is how you get

Code: Select all

&lt;option value=&quote;1&quote;&gt;1&lt;/option&gt;
when you have

Code: Select all

echo "<option value = '$i'>$i</option>";
when it should have been

Code: Select all

&lt;option value='1'&gt;1&lt;/option&gt;
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Well, I just cut and pasted the code from Firefox - it automatically converts ' to " .

In other news, I figured it out: I had those select boxes being generated in a function. That function is being called twice on the page I'm having the problem. So, hrs_spent and min_spent was being overwritten further down the page when I had hidden variables with the same name. I just stopped outputing them and the problem was fixed.

Thanks.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply