Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Checking radio with Mustache
<!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>
@bobthecow

This comment has been minimized.

Copy link

bobthecow commented Mar 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.