public
Last active

Checking radio with Mustache

  • Download Gist
radio_mustach_example.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/mustache.js"></script>
</head>
<body>
<div id="formWrapper">
 
</div>
 
<script id="tmpl" type="x-template">
<form>
{{#wrapped}}
<label><input type="radio" name="gender" value="male"> Male</label>
<label><input type="radio" name="gender" value="female"> Female</label>
{{/wrapped}}
</form>
</script>
 
<script type="text/javascript">
var data = {
gender: 'female',
wrapped:function () {
return function (text) {
return text.replace('value="' + this.gender+'"', 'value="' + this.gender+'" checked');
}
}
};
 
var template = $("#tmpl").html();
var result = Mustache.render(template, data);
 
$("#formWrapper").html(result);
 
</script>
 
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.