Segun entiendo.... al hacer submit deseas que se quede seleccionado el valor seleccionado anteriormente.......... y ps eso se hace asi......
Código html:
Ver original<?php
session_start();
//$_SESSION['name'] = "usuario1";
if(empty($_SESSION['name'])) header("Location:login.html");
$name = $_SESSION['name'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> var usuario1 = new Array("Seleccione la fruta","banana","pera","manzana","sandia");
var usuario2 = new Array("Seleccione la fruta","manzana","naranja");
var usuario3 = new Array("Seleccione la fruta","banana","toronja","uva");
function setSelect(){
fruta = '
<select name="fruta" id="fruta">';
for(a = 0; a < <?php echo $name; ?>.length; a++){
selected = (<?php echo $name; ?>[a] == <?php echo $_REQUEST['fruta']; ?>) ? "selected='selected'" : "";
fruta+= '
<option value="' + <?php echo $name; ?>[a] + '" ' + selected + '>' +
<?php echo $name; ?>[a] + '
</option>';
}
document.getElementById('select').innerHTML = fruta;
}
<body onload="setSelect()"> <form id="form1" action="" method="post">
agregue una validacion comparando el valor recorrido con el que viene del select fruta al hacer submit.
espero te sirva....
Suerte.