Skip to content

Instantly share code, notes, and snippets.

@pure
Created December 13, 2011 09:06
Show Gist options
  • Save pure/1471311 to your computer and use it in GitHub Desktop.
Save pure/1471311 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://github.com/pure/pure/raw/master/libs/pure.js"></script>
</head>
<body>
<form id="myForm"></form>
<script>
function displaySelectPerPure(targetObject,name,value,optionList){
var jsonData = {
'name':name,
options:[]
},
i = 0,
directiveData = {
'option':{
'option <- options':{
'.':'option.description',
'@value':'option.val',
'@selected':'option.sel'
}
}
},
sel = $('<label><b>' + name + '</b><select><option /></select></label>')
.appendTo(targetObject)
.find('select');
for (; i < optionList.length; i++) {
jsonData.options.push({
description: optionList[i],
val: optionList[i],
sel: value === optionList[i]
});
};
sel.render(jsonData,directiveData);
}
displaySelectPerPure($('form#myForm'),'Status', 'OFF', ['ON','OFF'] );
displaySelectPerPure($('form#myForm'),'Inherit', 'PRIMARY', ['PRIMARY','PERSONAL'] );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment