Skip to content

Instantly share code, notes, and snippets.

@sunaot
Created June 23, 2011 10:41
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 sunaot/1042326 to your computer and use it in GitHub Desktop.
Save sunaot/1042326 to your computer and use it in GitHub Desktop.
text for JavaScript lesson class.
<html>
<head>
</head>
<body>
<form id="input">
<textarea id="list" rows="20" cols="30"></textarea>
<input type="button" value="run" onclick="quoteNumbers()">
</form>
<pre id="result">
</pre>
</body>
<script type="text/javascript"><!--
function quoteNumbers() {
numbers = getList();
comma_nums = makeQueryParameter(numbers);
showResult(comma_nums);
}
function getList() {
return document.getElementById("list").value;
}
function showResult(result) {
document.getElementById("result").innerHTML = result;
}
String.prototype.eachRows = function() { return this.split(/\s/); }
function makeQueryParameter(list) {
reject_empty_row = function(row) {return row != '';};
surround_by_quote = function(item) { return "'" + item.toString() + "'"; };
return list.eachRows().filter(reject_empty_row).map(surround_by_quote).join(",\n");
}
// --></script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment