Welcome Guest, Not a member yet? Register   Sign In
Code does not seem to work?
#1

[eluser]Tom Glover[/eluser]
I have a clients website, in which I need it to write a form from and array.

In the view file:
Code:
<select name="relayletter2" id="relayletter">
            &lt;? if (is_array($letters)){
                  foreach ($letters as $letter)
                 {
                     if($letter === $selected)
                        {?&gt;
                        <option selected="selected" value="&lt;?=$letter?&gt;">&lt;?=$letter?&gt;</option>
                      &lt;?  }else{ ?&gt;
                           <option value="&lt;?=$letter?&gt;">&lt;?=$letter?&gt;</option>
                   &lt;?  }
                    }
                }?&gt;        
              </select>

The array that is passed to it:
Code:
$letters = array('a','b','c','d','e','...')

It is meant to compare that to what it is getting for the database, and when it finds a match it is meant to set the option selected.

At the Moment all options are selected.
#2

[eluser]Thoer[/eluser]
What does the good ol' var_dump test say? Smile
#3

[eluser]MadZad[/eluser]
Plus, can change this line
Code:
<option selected="selected" value="&lt;?=$letter?&gt;">&lt;?=$letter?&gt;</option>
to
Code:
<option selected="selected" value="&lt;?=$letter?&gt;">letter=&lt;?=$letter?&gt;, selected=&lt;?= $selected ?&gt;</option>
for further enlightenment.




Theme © iAndrew 2016 - Forum software by © MyBB