Created
June 23, 2011 10:41
-
-
Save sunaot/1042326 to your computer and use it in GitHub Desktop.
text for JavaScript lesson class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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