Skip to content

Instantly share code, notes, and snippets.

@taka2
Created July 17, 2009 10:56
Show Gist options
  • Select an option

  • Save taka2/149001 to your computer and use it in GitHub Desktop.

Select an option

Save taka2/149001 to your computer and use it in GitHub Desktop.
<html>
<head>
<script src = "prototype-1.6.0.3.js"></script>
<script language = "JavaScript">
var lineNumber = 1;
function addLine()
{
lineName = prompt("名前:");
if(lineName != null)
{
new Insertion.Bottom('inputTable', createLine(lineName, lineNumber));
lineNumber++;
}
}
function createLine(lineName, lineNumber)
{
var result = "";
result += "<tr>";
result += "<td>" + lineName + "<input type = \"hidden\" id = \"" + lineNumber + "\" value = \"0\"/></td>";
result += "<td><input type = \"button\" onClick = \" plus(" + lineNumber + ")\"value = \"+\"/></td>";
result += "<td><input type = \"button\" onClick = \" minus(" + lineNumber + ")\"value = \"-\"/></td>";
result += "<td><span id = \"counter" + lineNumber + "\"/></td>";
result += "</tr>";
return result;
}
function plus(id)
{
var val = $(id + '');
var counter = val.value;
counter++;
val.value = counter;
display(id, counter);
}
function minus(id)
{
var val = $(id + '');
var counter = val.value;
if(counter > 0)
{
counter--;
val.value = counter;
display(id, counter);
}
}
function display(id, counter)
{
var val = $('counter' + id);
val.innerHTML = makeDisplayData(counter);
}
function makeDisplayData(counter)
{
result = "";
for(i=0; i<counter; i++)
{
result += "☆";
}
return result;
}
</script>
</head>
<body>
<table id = "inputTable">
</table>
<p>
<input type = "button" onClick = "addLine()" value = "+"/>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment