PHP session og JAVA Dynamic select
Denne kode virker fint i FF men ville også gerne have den virkede i IE. Problemmet er når jeg har vælgt (her) først 2 også 234 og trykker submit, virker selected ikke rigtigt som det skal i IE, kun i FF. Ved ikke om det skyldes Java scripted.<?
session_start();
$_SESSION['pick'] = $_POST['pick'];
$_SESSION['i'] = $_POST['i'];
echo $_SESSION['pick'] ." - ". $_SESSION['i'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>SELECT</title>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
function dynamicSelect(id1, id2) {
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_mac = (agt.indexOf("mac") != -1);
if (!(is_ie && is_mac) && document.getElementById && document.getElementsByTagName) {
var sel1 = document.getElementById(id1);
var sel2 = document.getElementById(id2);
var clone = sel2.cloneNode(true);
var clonedOptions = clone.getElementsByTagName("option");
function to display the related options in the dynamic select box
refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
sel1.onchange = function() {
refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
};
}
}
function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
while (sel2.options.length) {
sel2.remove(0);
}
var pattern1 = /( |^)(select)( |$)/;
var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
for (var i = 0; i < clonedOptions.length; i++) {
if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
sel2.appendChild(clonedOptions[i].cloneNode(true));
}
}
}
window.onload = function() {
dynamicSelect("pda-brand", "pda-type");
}
</script>
</head>
<body>
<form action="<? $PHP_SELF ?>" method='post'>
<div>
<select id="pda-brand" name='pick'>
<?
for ($o = 1; $o <= 10; $o++) {
echo "<option value='".$o."'";
echo ($o == $_SESSION['pick']) ? " SELECTED" : "";
echo ">".$o."</option>";
}
?>
</select>
<select id="pda-type" name='i'>
<?
for ($i = 1; $i <= 10; $i++) {
echo "<option class='".$i."' value='".$i."'";
echo ($i == $_SESSION['i']) ? " SELECTED" : "";
echo ">".$i."</option>";
echo "<option class='".$i."' value='".$i."34'";
echo ("234" == $_SESSION['i']) ? " SELECTED" : "";
echo ">".$i."34</option>";
}
?>
</select>
<input type='submit' value='test'>
</form>
</body>
</html>