Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Created September 24, 2012 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ciantic/3774704 to your computer and use it in GitHub Desktop.
Save Ciantic/3774704 to your computer and use it in GitHub Desktop.
Testi
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Select test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
function Hae(kohde_id, porras_id, kerros_id, fill_name) {
$.getJSON("hae_data2.php",{kohde_id: kohde_id, porras_id: porras_id, kerros_id: kerros_id}, function(j){
console.log(j);
for (var i = 0; i < j.length; i++) {
var option = $("<option></option>")
.attr('value', j[i].id)
.text(j[i].nimi);
$(fill_name).append(option);
}
// $(fill_name+' option:last').attr('selected', 'selected');
});
}
$(function(){
$("#Testi").click(function(){
Hae(1,-1,-1,"#ctlPorras");
$("#ctlKerros").empty(); // Poistaa sisällä olevat HTML elementit
$("#ctlHuoneisto").empty();
});
$("#ctlPorras").change(function(){
$("#ctlHuoneisto").empty();
Hae(1,$("#ctlPorras").val(),-1,"#ctlKerros");
});
$("#ctlKerros").change(function(){
Hae(1,$("#ctlPorras").val(),$("#ctlKerros").val(),"#ctlHuoneisto");
});
});
</script>
</head>
<body>
<select size="20" id="ctlPorras">
</select>
<select size="20" id="ctlKerros">
</select>
<select size="20" id="ctlHuoneisto">
</select>
<button id="Testi">Hae</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment