経験ゼロからプロのSEを目指しているさまを書きなぐり★
初めてといっていいほど1からJS書きました。
テキスト追加したらセレクトのリストの中に追加され、
セレクトの中のを指定してボタン押すと削除されるというものを作りたかった。
最終的にはセレクト内のものをデータベースに登録する予定らしく、 「追加」・「削除」の度にデータベースアクセスするのもちょっとね・・・
というわけで作成してみました。
<script type="text/JavaScript">
<!--
function addList() {
len = document.form.list.length;
val = document.form.add.value;
if (val == "") {
return;
}
document.form.list.length += 1;
document.form.list.options[len].text = val;
document.form.add.value = "";
}
function delList() {
len = document.form.list.length;
for (i = 0; i < len; i++) {
if (document.form.list.options[i].selected == true) {
document.form.list.options[i].selected = false;
document.form.list.options[i] = null;
i--;
len--;
}
}
}
// -->
</script>
<<form name="form" action="JS.html" method="POST">
<table>
<tr>
<td bgcolor="#FFFFFF">
<input type="text" size=20 name="add" value="">
<input type="button" value="追加" onClick="addList()">
<br>
<select size=4 name="list" multiple>
</select>
<input type="button" value="削除" onClick="delList()"><br>
</td>
</tr>
</table>
</form>
こんな感じでいかがでしょうか。。。
実際のうごきはこちらからドゾー。
つっこみお待ちしております。
マジで今回はわからんかった!
調べても調べても出てこないし。。。
テキスト追加したらセレクトのリストの中に追加され、
セレクトの中のを指定してボタン押すと削除されるというものを作りたかった。
最終的にはセレクト内のものをデータベースに登録する予定らしく、 「追加」・「削除」の度にデータベースアクセスするのもちょっとね・・・
というわけで作成してみました。
<script type="text/JavaScript">
<!--
function addList() {
len = document.form.list.length;
val = document.form.add.value;
if (val == "") {
return;
}
document.form.list.length += 1;
document.form.list.options[len].text = val;
document.form.add.value = "";
}
function delList() {
len = document.form.list.length;
for (i = 0; i < len; i++) {
if (document.form.list.options[i].selected == true) {
document.form.list.options[i].selected = false;
document.form.list.options[i] = null;
i--;
len--;
}
}
}
// -->
</script>
<<form name="form" action="JS.html" method="POST">
<table>
<tr>
<td bgcolor="#FFFFFF">
<input type="text" size=20 name="add" value="">
<input type="button" value="追加" onClick="addList()">
<br>
<select size=4 name="list" multiple>
</select>
<input type="button" value="削除" onClick="delList()"><br>
</td>
</tr>
</table>
</form>
こんな感じでいかがでしょうか。。。
実際のうごきはこちらからドゾー。
つっこみお待ちしております。
マジで今回はわからんかった!
調べても調べても出てこないし。。。
PR