PDA

View Full Version : Selected attribute ignored in IE



Moswell
Jul 16th, 2009, 10:00 PM
I've got a page (http://www.moswell.people.haverford.edu/multiselect.php) on which I'm playing with various types of cascading select forms. I've got some php which is creating the select dropdowns and checking user input on a form to retain selected options. This is working like a charm in Firefox 3, but in Internet Explorer 8, even though when one looks at the code it clearly shows the <option selected="selected"> it's ignoring it in the actual printout. I've done some looking around here and elsewhere on the web, and I can't figure out why IE wouldn't honor the selected attribute. Any ideas?
Here's a snipped of the php code:

function book_select() {
$optiontwo = $_POST['sources'];
echo $optiontwo;
$query="SELECT Source.Source_ID, Book_Title, Composer.Comp_ID, Comp_Name FROM Source, Composer JOIN Writes ON Source.Source_ID = Writes.Source_ID AND Composer.Comp_ID = Writes.Comp_ID";
$result=mysql_query($query);
echo "<select name=\"sources\" id=\"sources\">
<option class=\"none\" value=\"none\">Select a Book</option>\n";
while ($row=mysql_fetch_array($result)) {
$sourceid = $row['Source_ID'];
echo "<option class=\"sub_$row[Comp_ID]\" value=\"$sourceid\"";
if ($sourceid == $optiontwo) {
echo ' selected="selected"';
}
echo ">$row[Book_Title]</option>\n";
}
echo "</select>";
}


And this is what prints out (even though in IE the selected item is not actually selected):

<option class="none" value="none">Select a Book</option>
<option class="sub_1" value="17">Ayres</option>
<option class="sub_2" value="29">The First Booke of Songs or Ayres</option>
<option class="sub_3" value="26">The Ayres that were sung and played at Brougham Castle</option>
<option class="sub_4" value="1">The First Booke of Ayres</option>
<option class="sub_5" value="2">Booke of Ayres with a Triplicitie of Musicke</option>
<option class="sub_6" value="8">Teares for the death of the Right Honorable the Earle of Devonshire</option>
<option class="sub_6" value="9">Songs of Mourning: Bewailing the untimely death of Prince Henry</option>
<option class="sub_7" value="12">Songs for the Lute Viol and Voice</option>
<option class="sub_8" value="13">Firste Booke of Songes or Ayres</option>
<option class="sub_8" value="14" selected="selected">Second Booke of Songs or Ayres</option>
<option class="sub_8" value="15">Third and Last Booke of Songs or Aires</option>
<option class="sub_8" value="16">A Pilgrimes Solace</option>
<option class="sub_10" value="27">XII Wonders of the World</option>
<option class="sub_11" value="7">(Title lost)</option>
<option class="sub_12" value="31">A Booke of Ayres</option>
<option class="sub_13" value="30">A Musicall Banquet</option>
<option class="sub_14" value="21">The First Booke of Songes and Ayres</option>
<option class="sub_14" value="22">The Second Booke of Songs and Ayres</option>
<option class="sub_14" value="23">Ultimum vale with Triplicity of Musicke</option>
<option class="sub_14" value="24">A Musicall Dreame or The Fourth Booke of Ayres</option>
<option class="sub_14" value="25">The Muses Gardin for Delights or The Fift Booke of Ayres</option>
<option class="sub_15" value="3">Two Bookes of Ayres (First Booke)</option>
<option class="sub_15" value="4">Two Bookes of Ayres (Second Booke)</option>
<option class="sub_15" value="5">The Third and Fourth Booke of Ayres (Third Book)</option>
<option class="sub_15" value="6">The Third and Fourth Booke of Ayres (Fourth Book)</option>
<option class="sub_16" value="18">Musicke of Sundrie Kindes</option>
<option class="sub_17" value="19">Songes of Sundrie Kindes</option>
<option class="sub_18" value="28">First Booke of Ayres</option>
<option class="sub_19" value="20">First Part of Ayres</option>
<option class="sub_20" value="10">Ayres to Sing and Play to the Lute and Basse Violl</option>
<option class="sub_20" value="11">The Second Book of Ayres</option>
</select>

Apostropartheid
Jul 16th, 2009, 10:10 PM
There is no selected element in that snippet of code, nor in the live page(?)

Moswell
Jul 16th, 2009, 10:14 PM
There is no selected element in that snippet of code, nor in the live page(?)

Doesn't this: <option class="sub_8" value="14" selected="selected">Second Booke of Songs or Ayres</option> mean it should be selected?

Apostropartheid
Jul 16th, 2009, 10:20 PM
IE does have support for this. Try removing all your JS and see what happens?

ckeyrouz
Jul 16th, 2009, 10:20 PM
I have tested the html output on IE8 version 8.0.6001.18702 and it is working fine.

VIPStephan
Jul 16th, 2009, 10:20 PM
Doesn't this: <option class="sub_8" value="14" selected="selected">Second Booke of Songs or Ayres</option> mean it should be selected?

Yes but the atrribute is nowhere in your code. Not in the code you posted and not in the code on your live site. Therefore it canít select anything that it isnít told to select.

ckeyrouz
Jul 16th, 2009, 10:24 PM
Excuse me VIPStephan but at first I did not see it as well.
In fact it exists:
<option class="sub_8" value="14" selected="selected">Second Booke of Songs or Ayres</option>

in the html output and inside an if statement in the php code:

if ($sourceid == $optiontwo) {
echo ' selected="selected"';
}

Moswell
Jul 16th, 2009, 10:25 PM
edit - I see ckeyrouz finally saw it too. :)

So, ckeyrouz, you're saying in IE you made some choices, hit the "get value" button, and all the values were retained? Now that I look at it a little closer, what I see is that the composer will be retained, but the book (if there's more than one) and the song (always more than one) will revert to the first option after submitting.

Moswell
Jul 16th, 2009, 10:33 PM
IE does have support for this. Try removing all your JS and see what happens?

Yeah, it must be the javascript that is affecting it somehow. I took out the javascript and just ran the php form here: http://www.moswell.people.haverford.edu/dd.php and it retains the proper selected values.

Darn it - I really don't know javascript well enough to fix it either. I picked up that code from elsewhere.

Moswell
Jul 16th, 2009, 10:56 PM
So I suppose I should transfer this over to the javascript forum and see if someone there can explain and/or fix why this works in firefox (and chrome too I think) and not IE?