Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.