Buonasera a tutti,
avrei un piccolo problemino con un script che, per mia poca conoscenza di javascript non riesco a risolvere. In pratica vorrei che al lato del menù a tendina dello script sottostante comparisse visualizzato, in tempo reale, il valore di "scuole" contenuto nel campo option.
In sostanza vorrei ottenere uan cosa del genere: http://i65.tinypic.com/x114qp.png
Come potrei fare?
Sinceramente grazie!
Codice PHP:
<?php
session_start();
//cancella i valori aggiunti nell'array
if(isset($_POST['reset']) && $_POST['reset'] == 'reset'):
foreach($_SESSION['ListItems'] as $key => $value) {
if ($value == $_POST['toreset']) {
unset($_SESSION['ListItems'][$key]);
continue;
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
endif;
?>
<html>
<head>
<title>form</title>
</head>
<body>
<form method="post" action="">
<table>
<tr>
<td><label for="item">aggiungi elemento</label></td>
<td><select name="item" id="item" class="form-control">
<option value="0">Seleziona la provincia...</option>
<option sigla="AG" scuole="22" zona="Agrigento" value="22">Agrigento</option>
<option sigla="AL" scuole="23" zona="Alessandria" value="23">Alessandria</option>
<option sigla="AN" scuole="24" zona="Ancona" value="24">Ancona</option>
</select>
</tr>
</table>
<input type="submit" name="invia" id="invia" value="aggiungi" />
</form>
<?php
//non registrare valori nulli
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['item'])):
if ($_POST['item'] != "0"):
//controlla se la sessione esiste, se no:
if(! isset($_SESSION['ListItems'])):
$items = array();
array_push($items, $_POST['item']);
$_SESSION['ListItems'] = $items;
//se esiste invece:
else:
if (!in_array($_POST['item'],$_SESSION['ListItems'] )) :
array_push($_SESSION['ListItems'], $_POST['item']);
endif;
endif;
endif;
endif;
//visualizza gli elementi soltanto se la sessione ListItems esiste
if(isset($_SESSION['ListItems'])):
foreach($_SESSION['ListItems'] as $value):
echo '<form method="post" action="">';
echo "$value";
echo "<input type='hidden' name='toreset' value='$value' />";
echo '<input type="submit" name="reset" id="reset" value="reset" /></form>';
endforeach;
echo '</ul>';
endif;
?>
</body>
</html>