Skip to content

Instantly share code, notes, and snippets.

@alistairstead
Created April 10, 2012 12:25
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 alistairstead/2351041 to your computer and use it in GitHub Desktop.
Save alistairstead/2351041 to your computer and use it in GitHub Desktop.
Node-1.js
<!DOCTYPE html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Node-1</title>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<link rel="stylesheet" href="http://yuilibrary.com/yui/docs/assets/node/node.css">
</head>
<body>
<form id="demo" action="#">
<label>Width:</label>
<input name="width" size="2">
<input type="submit" value="Run">
</form>
<script type="text/javascript">
YUI().use('node', function(Y) {
var form = Y.one('#demo'),
input = Y.one('#demo input[name=width]'),
button = Y.one('#demo input[type=submit]');
form.on('submit', function(e) {
e.preventDefault(); // keep the form from submitting
var value = input.get('value'),
width = form.get('offsetWidth');
if (value == '') {
input.set('value', width);
} else if (!isNaN(parseInt(value))) {
form.set('offsetWidth', value);
}
});
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment